2 ms·
Indeed, if your data need to be mutex protected might as well use a condition variable: it will be as efficient and certainly more understandable. Semaphore ma
by gpderetta 4y ago
Indeed, if your data need to be mutex protected might as well use a condition variable: it will be as efficient and certainly more understandable.
Semaphore make sense for one shot publishing: write the data -> signal -> wakeup then read the data, where some other invariant prevents reading the data before the wait. They also work somewhat well to add waiting on otherwise lock free queues.
In POSIX, condition variables are not async signal safe, so sem_t is a good alternative if needed.
On linux mutexes are farily