Using semaphore

Another Windows synchronization object is semaphore. Semaphore works as a narrow gate, which a certain number of threads can pass through at any instant of time. We will use our previous example again with slight changes to demonstrate various approaches with different synchronization objects and techniques while achieving the same results.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

Now, let's create our program and explain its structure.

  1. Create a new empty C++ Windows application named concurrent_operations2.
  2. Open Solution Explorer and right-click on Header file. Add the existing header file used in Chapter 1, Introduction to C++ Concepts and Features, named CQueue.h.
  3. Open Solution Explorer and right-click ...

Get C++ Multithreading Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.