.NET threading - Concepts
of Monitor class, the interlocked class and the ReaderWriterLock class -
March 13, 2009 at 15:20 PM by Amit Satpute
Describe the concepts of Monitor class, the interlocked class and the
ReaderWriterLock class.
Access to objects by is controlled by the Monitor class. It grants a lock for an
object to a single thread.
Critical sections can be access restricted by using object locks.
While a thread owns the lock for an object, no other thread can acquire that
lock.
Interlocked class provides atomic operations for variables that are shared by
multiple threads.
When two threads are executing concurrently on separate processors error
protection is done.
The methods of this class help protect against errors that can occur when the
scheduler switches contexts while a thread is updating a variable that can be
accessed by other threads.
ReaderWriterLock synchronizes access to a resource. It allows either concurrent
read access for multiple threads, or write access for a single thread.
A ReaderWriterLock provides better throughput than a simple one lock a time
like Monitor.
|