2 ms·
Not really contention, but for example a common event semaphore pattern for multiple producer/single consumer is on the consumer side Test condition (e.g. q
by bonzini 9y ago
Not really contention, but for example a common event semaphore pattern for multiple producer/single consumer is on the consumer side
Test condition (e.g. queue not empty)
If false,
Reset event
Test condition again
If false,
Wait on event
The event stays set most of the time, which helps reducing cacheline bounces between the producers even if you don't have contention; so even if you use lock free atomic operations with optimistic spinning for the busy case, (event) semaphores can then still be used when the worker goes to sleep.
The event itself can be implemented as a mutex/condvar pair, alternatively, but that's pointless if you document what you are doing and do it consistently.