Summary
In this chapter, we explored several topics related to concurrency and parallelism in C++. We began by discussing the terminology and differences between concurrency and parallelism, including preemption. We then delved into how programs execute on single and multiple processing units, distinguishing between processes and execution threads and briefly exploring communication mechanisms such as pipes, sockets, and shared memory.
In the context of C++, we examined how the language supports concurrency, specifically through the std::thread
class and the new std::jthread
primitive introduced in C++20. We also discussed the risks associated with race conditions and data races, including an example of a money transfer operation. To avoid these issues, we examined mechanisms such as locks, atomic operations, and memory barriers.
Moving on, we looked closely at the std::jthread
class, exploring its functionality and proper usage. Additionally, we learned about a new synchronized...