I'm using a semaphore to control access of multiple concurrent threads.
It would be nice if the semaphore could preferably enable those threads that have waited the longest, instead of just randomly picking one. In other words, it should have some notion of fairness.
The documentation on semaphores mentions they are not fair:
There is no guaranteed order, such as FIFO or LIFO, in which blocked threads enter the semaphore.
How should I go about creating such a semaphore?