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.
When a thread finishes using the resource, it gives back the semaphore, waking any other threads which were also waiting for it.
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).
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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.