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

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.