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

Synchronization wrappers and how to implement them

In this recipe, we will learn how to make thread-safe synchronization wrappers. By default, the C++ standard library is not thread-safe as not all applications will need this functionality. One mechanism to ensure the C++ standard library is thread-safe is to create a thread-safe class, which adds the data structure you wish to use as well as std::mutex to the class as private members, and then reimplements the data structure's functions to first acquire std::mutex and then forward the function call to the data structure. The problem with this approach is there is a lot of extra code that is added to your program if the data structure is a global resource, making the resulting code hard to ...

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