0 Replies Latest reply on Apr 7, 2018 9:15 AM by avatli

    Accessing a 64-bit variable from different threads without synchronization or atomicity


      I have two posix threads sharing an uint64_t global variable.


      The first thread just reads from the variable while the other thread just writes into. If I don't synchronize the two threads using mutex/spinlock/atomic operations etc.., is there any possibility of reading another value from the writing thread wrote into? It is not important to read an old-value which was written by writing thread in the previous run.


      As an example, the writing thread increases the variable between 0 and 100, and the reading thread prints the value. So, is there any possibility to see a value in the screen different than [0-100] range. Currently I don't see any different value but I'm not sure it can cause a race condition. Is there any possibility that a compiler maps the uint64_t variable in two different virtual pages or accessing the uint64_t variable in two different cycle.


      Is 64-bit memory access always atomic?



      Thanks in advance. 


      - Volkan