O'Reilly logo

C++ Multithreading Cookbook by Milos Ljumovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required