Using Basic Synchronization Primitives

The following sections describe the basic .NET synchronization primitives. Each of these classes can be used to ensure that only one Task is able to enter a critical region. The next chapter will describe some advanced synchronization primitives that will allow you to work with different numbers of Tasks.

Table 3-1. Synchronization Primtives




Serialize access to a critical region.

Use the lock keyword or System.Threading.Montor class, or use the System.Threading.SpinLock class.

3-6, 3-7, and 3-10

Increment or decrement a numeric value.

Use the static members of the System.Threading.Interlocked class.

and 3-9

Create cross process synchronization.

Use the System.Threading.Mutex class to create a named mutex.


Perform synchronization using multiple locks.

Use WaitAll() method of a primitive that extends System.Threading.WaitHandle.


Synchronize all of the methods in a class.

Use declarative synchronization.


Create locks that permit multiple readers.

Use a reader-writer lock.

3-15 and 3-16

0 0

Post a comment