FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
October 01, 2003

Threading from Managed C++

(Page 4 of 7)
Threading from Managed C++

Listing 3: A lock block

#using <mscorlib.dll>
using namespace System;
using namespace System::Threading;

class ArrayManip
{
public:
   static int TotalValues(int array __gc[])
   {
/*1*/      int sum = 0;

/*2*/      Monitor::Enter(array);
      for (int i = 0; i < array.Length; ++i)
      {
         sum += array[i];
      }
      Monitor::Exit(array);

      return sum;
   }

   static void SetAllValues(int values __gc[], int newValue)
   {
/*3*/      Monitor::Enter(values);
      for (int i = 0; i < values.Length; ++i)
      {
         values[i] = newValue;
      }
      Monitor::Exit(values);
   }
— End of Listing —
Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK