Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Synchronization is the act of coordinating concurrent actions for a predictable outcome. Synchronization is particularly important when multiple threads access the same data; it’s surprisingly easy to run aground in this area.
The simplest and most useful synchronization tools are arguably the continuations and task combinators we described in Chapter 14. By formulating concurrent programs into asynchronous operations strung together with continuations and combinators, you lessen the need for locking and signaling. However, there are still times when the lower-level constructs come into play.
The synchronization constructs can be divided into three categories:
Exclusive locking constructs allow just one thread to perform
some activity or execute a section of code at a time. Their primary
purpose is to let threads access shared writing state without
interfering with one other. The exclusive locking constructs are
lock, Mutex (and SpinLock).