Implement an extended semaphore
Closed this issue · 1 comments
yruslan commented
Background
Classic semaphore uses 2 methods:
- P() - decrement and wait
- V() - increment.
While a semaphore provides good means of controlling shared resource usage, issues like 'the dining philosophers problem' can arise when a thread needs to consume more than one resource to function.
Feature
Create an extended semaphore that provides
- P(n) - consume n items or wait until they are available
- V(n) - return n items
This can only work if waiting threads wait for resources in FIFO order. Otherwise, threads that require only 1 resource will take precedence and can create liveness issues for threads that require more than 1.
yruslan commented
Standard Java semaphores support this it seems.