Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

Working with mutexes

In this recipe, we will learn why and how to use a mutex in C++. When working with multiple threads in C++, it is common to establish resources that are shared between threads. As we will demonstrate in this recipe, attempting to use these shared resources simultaneously leads to race conditions that are capable of corrupting the resource.

A mutex (in C++, this is written as std::mutex) is an object that is used to guard a shared resource, ensuring that more than one thread can access a shared resource in a controlled manner. This prevents it from becoming corrupt.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content