Synchronization

Using the techniques from Listing 23.1, it's easy to create multiple threads of execution. As long as each thread minds its own business, the program runs fine. However, in many situations, this is not practical. It's often necessary for multiple threads to share a resource. Without control, the behavior of multi-threaded programs sharing a resource yields non-deterministic results.

To provide that control, C# allocates methods to coordinate activities between threads. This coordination is properly termed synchronization. Correct implementation of synchronization enables programs to take advantage of performance benefits of multi-threading as well as maintaining the integrity of object state and data.

This section uses the C# ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.