thread synchronization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cmrchs@yahoo.com

    #1

    thread synchronization

    Hi,

    how can I synchronize 2 threads using the 'lock'-equivalent that is available in C# ?

    thanks
    Chris

    *************** *************** *************** *************** **********
    Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
  • Carl Daniel [VC++ MVP]

    #2
    Re: thread synchronization

    Chris C wrote:[color=blue]
    > Hi,
    >
    > how can I synchronize 2 threads using the 'lock'-equivalent that is
    > available in C# ?[/color]

    Managed code or native?

    If managed, you can use the same mechanism that C# uses: the
    System.Threadin g.Monitor class - you just have to call the member functions
    explicitly while the C# lock construct calls them for you.

    If native, depending on what you need, you might use a CriticalSection ,
    Mutex, Semphore or Event.

    http://msdn.microsoft.com/library/de...on_objects.asp

    is a good jumping-off point for information about the kernel synchronization
    objects (Mutex, Semaphore, Event), while

    http://msdn.microsoft.com/library/de...on_objects.asp

    covers CriticalSection s (which are not kernel objects - they're implemented
    by the win32 subsystem).

    -cd


    Comment

    • Jochen Kalmbach [MVP]

      #3
      Re: thread synchronization

      Hi Carl!
      [color=blue][color=green]
      >>how can I synchronize 2 threads using the 'lock'-equivalent that is
      >>available in C# ?[/color]
      >
      > If managed, you can use the same mechanism that C# uses: the
      > System.Threadin g.Monitor class - you just have to call the member functions
      > explicitly while the C# lock construct calls them for you.[/color]

      Just as an addition, here is a small code-sample (because this will be
      mostly implemented without the __try-__finally):

      C#:
      lock(obj)
      {
      // Some code
      }

      managed C++:
      System::Threadi ng::Monitor::En ter(obj);
      __try
      {
      // Some code
      }
      __finally
      {
      System::Threadi ng::Monitor::Ex it(obj);
      }

      --
      Greetings
      Jochen

      My blog about Win32 and .NET

      Comment

      Working...