The .NET Framework has some built-in signaling primitives that help us synchronize multiple threads without us having to write lots of synchronization logic. All the synchronization is handled internally by the provided data structures. In this section, let's discuss two very important signaling primitives: CountDownEvent and Barrier:
-
CountDownEvent: The System.Threading.CountDownEvent class refers to an event that's signaled when its count becomes 0.
- Barrier: The Barrier class allows multiple threads to run without having the master thread controlling them. It creates a barrier that participating threads must wait in until all the threads have arrived. Barrier works well for cases where work needs to be carried out in parallel and in phases.