C++ – How to Manage Threads Effectively

cdesignmultithreading

We use pthread for thread management in C based systems. pthread is in general compilable by C++ compiler (like g++). However, what are the better ways of abstractions for threads in C++?

Also, for making any system to be working in a multi-threaded system, it is also important to make thread safe. What are the standard libraries that requires alternative (installs) to be thread safe or are they unsafe for multi-threaded environments?

Is smart pointers, templates require special measures to make it safe?

What are the best practices for the thread managements in C++?

Best Answer

If you use C++11, threading is part of standard library and components where it makes sense like smart pointers are thread-safe (collections generally require you lock them yourself).

If you are using Boost, have a look at boost.thread. It is base for what was standardized in C++11 (most new things in C++11 come from boost).

Related Topic