POSIX’ condition variables pthread_cond_t
unfortunately have some drawbacks:
-
They require the use of at least two separate other objects that are only loosely coupled with the condition variable itself:
- A plain variable, say
X
of typeint
, that actually holds the value of which the condition depends. - A mutex that is just to regulate the access to
X
and to the condition variable.
- A plain variable, say
-
Generally they are not lock free. To access X we have to
- lock the mutex
- inspect X
- eventually wait for the condition to become true
- do changes
- eventually signal other waiters about the changes we made
- unlock the mutex
Linux’ concept of futexes allows to associate an equivalent concept directly to the variable X
and to access this variable without taking locks directly in most of the cases.
Continue reading “linux futexes: non-blocking integer valued condition variables”