32-bit and 64-bit atomic operations

Source: Internet
Author: User
This is part of the interlocked API introduced by Microsoft, but the atomic operation problem is mentioned in it. Although it should be only for Microsoft operating systems, I think all operating systems should be consistent. For a numeric operation that has the same or lower CPU bits and is aligned with bytes, the value assignment must be completed. After the assignment, the value must be assigned, after the value is obtained, it must be a value assigned to the value, and no median value exists. Therefore, the 32-bit integer may not cause errors if only one thread writes a value and other threads read the value. If multiple threads are used for reading and writing, but if multiple threads only use it as a bool value and are notified by the bool value, they do not care about the corresponding multi-thread. I think there should be no such use. Interlocked variable access

Applications must synchronize access to variables that are shared by multiple threads. Applications must also ensure that operations on these variables are saved med atomically (stored med in their entirety or not at all .)

Simple reads and writes to properly-aligned 32-bit variables are atomic operations. in other words, you will not end up with only one portion of the variable updated; all bits are updated in an atomic fashion. however, access is not guaranteed to be synchronized. if two threads are reading and writing from the same variable, you cannot determine if one thread will perform its read operation before the other performs its write operation.

Simple reads and writes to properly aligned 64-bit variables are atomic on 64-bit windows. reads and writes to 64-bit values are not guaranteed to be atomic on 32-bit windows. reads and writes to variables of other sizes are not guaranteed to be atomic on any platform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.