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 mutex

One of the Windows synchronization objects is mutex. We use mutex when we want to acquire exclusive access to some shared object. We also use mutex when we want to protect some part of the code, to be executed by one thread at a time.

In our following example, we will ask the user to provide a text file with six integer coordinates on each line in order to calculate a system of two linear equations:

Using mutex

We will also use the CQueue class, previously implemented in Chapter 1, Introduction to C++ Concepts and Features. Our task is to load all the values from the file, and then each group of coordinates will be added to the queue. When each group ...

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