0

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?

1 Answers1

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