Understanding the C++ Memory Model
This chapter is a continuation of the discussion from Chapter 7, where we discussed a few multiprocess and multi-threaded techniques; this chapter will enhance their usage. We will guide you through various techniques while narrowing down to the main focus of the chapter – the C++ memory model. But in order to discuss this, you will start first with a brief examination of memory robustness through the smart pointer and the optional objects. We will use them later to implement lazy initialization and handle shared memory regions safely. An improved memory access analysis of cache-friendly code follows. You will learn when and why using multi-threaded execution could be a trap, even though you did everything right in the software design.
This chapter gives you the opportunity to broaden your understanding of the synchronization primitives. While learning about the condition variables, you will also understand the benefits of the read-write...