From the course: Parallel and Concurrent Programming with C++ Part 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Semaphore

Semaphore - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 2

Start my 1-month free trial

Semaphore

- [Instructor] A semaphore is another synchronization mechanism that can be used to control access to shared resources sort of mike a mutex, but unlike a mutex a semaphore can allow multiple threads to access the resource at the same time, and it includes a counter to track how many times it's been acquired or released. As long as the semaphore's count value is positive, any thread can acquire the semaphore which then decrements that counter value. If the counter reaches zero then threads trying to acquire the semaphore will be blocked and placed in a queue to wait until it's available. When a thread is done using the resources it releases the semaphore which increments that counter value. And if there are any other threads waiting to acquire the semaphore, they'll be signaled to wake up and do so. - Hmm, looks like my phone's about to die. - Lucky us there's a charger right here. - Nice. This charger has…

Contents