The following tables summarize the .NET tools available for coordinating or synchronizing the actions of threads:
1 Simple Blocking Methods
| Construct | Purpose |
| Sleep | Blocks for a given time period |
| Join | Waits for another thread to finish |
2 Locking Constructs
| Construct | Purpose | Cross Process? | Speed |
| Lock | Ensures just one thread can access a resource, or section of code. | No | Fast |
| Mutex | Ensures just one thread can access a resource, or section of code. Can be used to prevent multiple instances of an application from starting. | Yes | Moderate |
| Semaphore | Ensures not more than a pecified number of therads can access a resource, or section of code. | Yes | Moderate |
(Synchronization Context are also provided, for automatic locking)
3 Signaling Constructs
| Construct | Purpose | Cross Process? | Speed |
| EventWaitHandle | Allows a thread to wait until it receives a signal from another therad. | Yes | Moderate |
| Wait & Pulse | Allows a thread to wait until a custom blocking condition is met. | No | Moderate |
4 Non-Blocking Synchronization Constructs
| Construct | Purpose | Cross Process? | Speed |
| Interlocked | To perform simple non-blocking atomic operations. | Yes (Assuming shared memory) | Very fast |
| volatile | To allow safe non-blocking access to individual fields outside of a lock. | Yes (Assuming shared memory) | Very fast |
No comments:
Post a Comment