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 critical section

Another Windows synchronization object is critical section. Critical section behaves in the same manner as mutex. However, it can be used only in a single process context, as opposed to mutex, which can be shared among multiple processes. However, a critical section object is allocated faster by the system, with much smaller overhead.

Our following example will use the same task as before, only this time, we will use critical section instead of mutex. We can use critical section here because our entire application executes in a single process context.

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

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