Atomic integer operations p176

Source: Internet
Author: User
Typedef struct {int counter;} atomic_t; # ifdef config_64bittypedef struct {long counter;} atomic64_t; # endif

The Linux kernel uses the Special Data Type atomic_t instead of the integer type that uses the C language directly, which is due to the following reasons:

(1) The atomic_t function only accepts the atomic_t type.

(2) Using the atomic_t type can avoid Compiler Optimization. Atomic operations are very important to using the correct memory address.

(3) The CPU architecture can be avoided.

 

There is a problem here, why can we avoid the cause by using struct? (2) the compiler is not optimized,

Google.

 

GCC does not reorder the elements of a struct, because that wowould violate the C standard. section 6.7.2.1 of the c99 standard states:

Within a structure object, the non-bit-memory eld members and the units in which bit-memory ELDS reside have addresses that increase in the order in which they are declared.

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.