A race condition occurs when simultaneous operations access shared data or resources and the result depends on which operation finishes first. The defect makes behavior unpredictable and difficult to debug. section 16.1
A singleton creation race
Suppose several threads call ExecutivePass::obtain() while the singleton does not yet exist. Each thread may observe single_instance as nullptr and create an object; the pointer then refers to whichever object was created last. The intended single object has become multiple objects because creation was not synchronized. section 14.1.4
Figure 16.1 A multithreaded application with three threads. The threads share the application’s internal resources of code and data in memory and external resources such as printers and files. The runtime system gives each thread its own runtime stack and the appearance of having its own set of machine registers.
Use the shared-resource diagram to trace how threads access memory, files, printers, and other resources concurrently. section 16.1



















