How can you use a semaphore to create a special critical section that allows two threads to be executing inside instead of the usual one thread?
Asked
Active
Viewed 132 times
0
-
Conceptually or for a specific language? – rene Sep 02 '13 at 19:36
-
3http://stackoverflow.com/questions/10898022/differnce-between-counting-and-binary-semaphores. – Pradheep Sep 02 '13 at 19:36
1 Answers
0
In pseudocode it looks like so:
s = Semaphore(2) # max 2 possible threads accessing the critical section
Each thread then uses the semaphore to serialize access:
s.decrement() # may block
# enter critical section
s.increment()
Useful resource is: The Little Book of Semaphores

jev
- 2,023
- 1
- 17
- 26