|
|
Any thread can potentially access any object in the program (objects with automatic and thread-local storage duration may still be accessed by another thread through a pointer or by reference). Different threads of execution are always allowed to access (read and modify) different memory locations concurrently, with no interference and no synchronization requirements. When an evaluation of an expression writes to a memory location and another evaluation reads or modifies the same memory location, the expressions are said to conflict. A program that has two conflicting evaluations has a data race unless . both evaluations execute on the same thread or in the same signal handler, or . both conflicting evaluations are atomic operations (see std::atomic), or . one of the conflicting evaluations happens-before another (see std::memory_order) If a data race occurs, the behavior of the program is undefined. (in particular, release of a std::mutex is synchronized-with, and therefore, happens-before acquisition of the same mutex by another thread, which makes it possible to use mutex locks to guard against data races) http://en.cppreference.com/w/cpp/language/memory_model#Threads_and_data_races |
Each function has its own memory space, including multiple calls of the same function |
This is often seen by understanding recursion, where the function [...] calls itself (new memory, new instance of the code), |