Problem
- Assume
static std::atomic<double> dataX =0.0;defined in a cpp(Module) - In that module two separate functions have been defined.
- These functions will be invoked and run by two threads independently,under the hood(within functions) two continuous looping processes are defined there; until
some break statement gets called(using predicate). - When the two functions are running one function responsible for writing data to
dataXand other function responsible for reading fromdataXand then post it to a container. - These two execution of functions happen under two threads as described and each thread gets sleep for very tiny millisecond(1ms) of duration.
- Therefore both Read/Write operations for
dataXcoupled and gets called within very less amount of CPU cycle time.
How does C/C++ run-time behave such condition for std::atomic<double> ?
Can we have a guarantee about both written and read values of std::atomic<double> dataX maintained such condition?