Condition variables

A CV is an inter-thread event notification mechanism. Where we use the mutex lock to synchronize (serialize) access to a critical section, thus protecting it, we use condition variables to facilitate efficient communication—in terms of synchronizing based on the value of a data item—between the threads of a process. The following discussion will make this clearer.

Often, in multithreaded application design and implementation, one is faced with this type of situation: a thread, B, is performing some work and another thread, A, is awaiting the completion of that work. Only when thread B completes the work should thread A continue; how can we efficiently implement this in code?

Get Hands-On System Programming with Linux 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.