Lock-Free-cas atomic operation

Source: Internet
Author: User

CAS atomic Operations--compare & Set, or Compare & Swap, now almost all CPU instructions support CAS atomic operations, X86 corresponding to CMPXCHG assembly instructions.

You should remember the concept of "atomic manipulation" inside the operating system, where an operation is atomic (atomic), and if the upper layer of this operation is not able to find its internal implementation and structure. An atomic operation can be a step or multiple steps, but its order cannot be disrupted, or it can be cut off only the execution part. With this atomic operation, we can achieve no lock.

Relative with lock ... Speed has improved

          scene: Multiple variables synchronize atomic update, and In the case of fierce thread competition, CPU consumption is more serious.

Problem:ABA: A thread modifying the V-value hypothesis is a, first modified to B, then modified back to a. The current thread's CAS operation cannot tell if the current V value has changed

Lock-Free-cas atomic operation

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.