1 Reply Latest reply on Jul 24, 2018 12:20 PM by Intel Corporation

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

    avatli

      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

        • 1. Re: Accessing a 64-bit variable from different threads without synchronization or atomicity
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello avatli,
            Thank you for patience and for joining this community.
          In this case, the support for your case needs to be addressed through one special area of support: Intel® Developer Zone.
          In order to help you further, the Development manuals are located here: https://software.intel.com/en-us/articles/intel-sdm
          You can start with the volume Volume 3 which includes the full system programming guide, parts 1, 2, 3, and 4. It describes the operating-system support environment of the Intel® 64 and IA-32 architectures, including: memory management, protection, task management, interrupt and exception handling, multi-processor support, thermal and power management features, debugging, performance monitoring, system management mode, virtual machine extensions (VMX) instructions, Intel® Virtualization Technology (Intel® VT), and Intel® Software Guard Extensions (Intel® SGX).
          For further questions please submit your ticket here:
          https://software.intel.com/en-us/home
          For personalized support contact a FAE (Field Application Engineer) via Intel Authorized Distributor/Reseller for access to Intel Premier Support.
          I hope this helps.
           Regards,
          Diego S.