Semaphores have two usages:
- Guard the critical section and resources, to provide the mutual exclusion
- Send signals between two processes or threads
In the constructor, one can specify the fairness settings. Fairness is each time when a permit is released, the longest thread waiting in queue will acquire it. This can guarantee no thread needs to wait in the queue all the time. Therefore, starvation can be prevented in this way.