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 5 of 7)
Threading from Managed C++

Listing 4: Inventing lock blocks and synchronizing on them

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

__gc class Th04
{
private:
   static Object *fileLock = new Object;

public:
   static void M1()
   {
      // ...
      Monitor::Enter(fileLock);
      try
      {
         // read from a file
      }
      __finally
      {
         Monitor::Exit(fileLock);
      }
      // ...
   }

   static void M2()
   {
      // ...
      Monitor::Enter(fileLock);
      try
      {
         // update a display
      }
      __finally
      {
         Monitor::Exit(fileLock);
      }
      // ...
   }
};
— 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