3. Synchronization
“That’s right!” said the Tiger-lily. “The daisies are worst of all.When one speaks, they all begin together, and it’senough to make one wither to hear the way they go on!”
—Lewis Carroll, Through the Looking-Glass
To write a program of any complexity using threads, you’ll need to share data between threads, or cause various actions to be performed in some coherent order across multiple threads. To do this, you need to synchronize the activity of your threads.
Section 3.1 describes a few of the basic terms we’ll be using to talk about thread synchronization: critical section and invariant.
Section 3.2 describes the basic Pthreads synchronization mechanism, the mutex.
Section 3.3 describes the condition variable, a mechanism ...
Get Programming with POSIX ® Threads 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.