Multithreaded Programming with C++ - Gregoire, Marc (Professional C++, 2018)
A professional C++ programmer needs to know how to write correct multithreaded code to take full advantage of all the available processor units. Writing multithreaded applications used to rely on platform‐ and operating system‐specific APIs. This made it difficult to write platform‐independent multithreaded code. C++11 solved this problem by including a standard threading library. A difficult part of multithreaded programming is making the algorithm parallel, which is highly dependent on the type of the algorithm. Other difficulties are preventing race conditions, deadlocks, tearing, and false‐sharing. This chapter discusses these difficulties in more detail. They are usually solved using atomics or explicit synchronization mechanisms. Launching a new thread is pretty easy. However, in most cases the programmers are probably interested in results produced by the thread. There is one easier method to obtain a result from threads: futures.