Hello everyone,
The (proprietary) OS I've been working with provides two "types"
of semaphores: fifo or prio. They differ in how callers of the
wait function are handled.
When the semaphore count is 0, callers of wait on a fifo semaphore
are stored in FIFO order in the wait queue, without consideration
for the thread's priority.
Callers of wait on a prio semaphore are stored in decreasing
priority order, thus higher priority thread will be signaled
before lower priority threads, even if they were late to the
party.
Looking at POSIX semaphores, and sem_wait specifically, I'm
wondering what kind of strategy is implemented on typical
POSIX platforms, and on recent Linux kernels?
Since POSIX doesn't specify this, I suppose implementations
are free to decide whatever strategy they prefer?
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
This statement might be relevant:
Applications using these functions may be subject to priority
inversion, as discussed in XBD Priority Inversion.
3.285 Priority Inversion
A condition in which a thread that is not voluntarily suspended
(waiting for an event or time delay) is not running while a lower
priority thread is running. Such blocking of the higher priority
thread is often caused by contention for a shared resource.
AFAICT, priority inversion could happen on either fifo or prio
semaphores, since the problem comes not from how waiters are
handled, but from a third unrelated medium-priority thread.
Regards.