Lock command in x86

Source: Internet
Author: User

the lock prefix applies to a single command, it has no impact on the interruption, because the interruption can only be generated between commands. The true function of the lock prefix is to keep control of the system bus until the entire command is executed. It is quite useful when a command accesses the memory multiple times.

for example, if you want to share a counter, perform the atomic increment operation on it. You need to do the following:


1) read the counter value from the memory, temporarily save it in the CPU internal register.
2) Add the read value.
3) write the modified value back to the memory.

In the X86 architecture, This incremental operation can be completed in a single command, so interruption does not affect this incremental operation. however, this command has two memory access operations: Read and Write. The other CPU or core may increment the counter at the same time. If another CPU/core (CORE) reads the value of this counter before the completion of step 2 and the completion of step 2, then the two CPU/core (CORE) use the previously modified counter value and increment it. In this case, an error occurs.

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.