Two tasks wait for the same event

tzuchien_chiu wrote on Friday, September 15, 2006:

Hello, all:

With the only schronization object binary semaphore (implemented by a queue), how could I simulate that more than one tasks simulatenously wait for one single resource?

For example, a Win32 event. Multiple threads can wait/block on the same event. Once the event is "set", all those threads are resumed.

nobody wrote on Friday, September 15, 2006:

When a thread finishes using the resource, it gives back the semaphore, waking any other threads which were also waiting for it.

tzuchien_chiu wrote on Friday, September 15, 2006:

The binary semaphore is implemented by a queue of length one. Once the element is recevied by a blocking task, the queue is empty and the other tasks cannot be waked (received anything from the queue).

nobody wrote on Friday, September 15, 2006:

Right, then the formerly-blocking task that was awakened first gives the semaphore back when it’s done (putting it back onto the queue), and wakes up the next blocking task in line, which also gives the semaphore back when it’s done, waking up the next blocking task, and so on.