The ???Win32 Synchronization Objects and WaitHandle??? section discusses
the pros and cons of the WaitHandle class. Since you implement the Mutex using a kernel Mutex,
you incur a transition to kernel mode any time you manipulate or wait upon the Mutex. Such
transitions are extremely slow and should be minimized if you??™re running time-critical code.
nTip Avoid using kernel mode objects for synchronization between threads in the same process if at all
possible. Prefer lighter weight mechanisms, such as the Monitor class or the Interlocked class. When
effectively synchronizing threads between multiple processes, you have no choice but to use kernel objects.
On a current test machine, a simple test showed that using the Mutex took more than 44 times longer than
the Interlocked class and 34 times longer than the Monitor class.
Events
In .NET, you can use two types to signal events: ManualResetEvent and AutoResetEvent. As
with the Mutex object, these event objects map directly to Win32 event objects. Similar to Mutex
objects, working with event objects incurs a slow transition to kernel mode. Both event types
become signaled when someone calls the Set method on an event instance. At that point, a
thread waiting on the event will be released.
Pages:
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492