久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

“鎖"有什么作用?x86匯編中的指令是什么意思

What does the quot;lockquot; instruction mean in x86 assembly?(“鎖有什么作用?x86匯編中的指令是什么意思?)
本文介紹了“鎖"有什么作用?x86匯編中的指令是什么意思?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 Qt 的源代碼中看到了一些 x86 程序集:

I saw some x86 assembly in Qt's source:

q_atomic_increment:
    movl 4(%esp), %ecx
    lock 
    incl (%ecx)
    mov $0,%eax
    setne %al
    ret

    .align 4,0x90
    .type q_atomic_increment,@function
    .size   q_atomic_increment,.-q_atomic_increment

  1. 通過谷歌搜索,我知道lock指令會導致CPU鎖定總線,但我不知道CPU何時釋放總線?

  1. From Googling, I knew lock instruction will cause CPU to lock the bus, but I don't know when CPU frees the bus?

關于上面的整個代碼,我不明白這段代碼是如何實現Add的?

About the whole above code, I don't understand how this code implements the Add?

推薦答案

  1. LOCK 本身不是一條指令:它是一個指令前綴,適用于后面的指令.該指令必須是對內存(INCXCHGCMPXCHG 等)執行讀-修改-寫操作的指令——在此如果是 incl (%ecx) 指令,inclong 字修改為 ecx注冊.

  1. LOCK is not an instruction itself: it is an instruction prefix, which applies to the following instruction. That instruction must be something that does a read-modify-write on memory (INC, XCHG, CMPXCHG etc.) --- in this case it is the incl (%ecx) instruction which increments the long word at the address held in the ecx register.

LOCK 前綴確保 CPU 在操作期間擁有適當緩存行的獨占所有權,并提供某些額外的排序保證.這可以通過斷言總線鎖定來實現,但 CPU 將在可能的情況下避免這種情況.如果總線被鎖定,那么它只是在鎖定指令的持續時間內.

The LOCK prefix ensures that the CPU has exclusive ownership of the appropriate cache line for the duration of the operation, and provides certain additional ordering guarantees. This may be achieved by asserting a bus lock, but the CPU will avoid this where possible. If the bus is locked then it is only for the duration of the locked instruction.

這段代碼將要遞增的變量的地址從堆棧復制到ecx寄存器中,然后它以原子方式執行lock incl (%ecx)將該變量加 1.如果變量的新值為 0,則接下來的兩條指令將 eax 寄存器(保存函數的返回值)設置為 0,否則設置為 1.該操作是一個增量,而不是一個添加(因此得名).

This code copies the address of the variable to be incremented off the stack into the ecx register, then it does lock incl (%ecx) to atomically increment that variable by 1. The next two instructions set the eax register (which holds the return value from the function) to 0 if the new value of the variable is 0, and 1 otherwise. The operation is an increment, not an add (hence the name).

這篇關于“鎖"有什么作用?x86匯編中的指令是什么意思?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 成人美女免费网站视频 | 黄色毛片在线看 | 日韩av大片免费看 | 91麻豆精品国产91久久久久久久久 | 亚洲 日本 欧美 中文幕 | 日日操夜夜干 | 国产精品91网站 | 成人影院在线观看 | 日本三级做a全过程在线观看 | 国产精品视频偷伦精品视频 | 一本大道久久a久久精二百 欧洲一区二区三区 | 精品美女久久久 | 成人做爰9片免费看网站 | 四虎影院美女 | 精品国产乱码久久久久久a丨 | 国产精品久久久久久久午夜片 | 一级毛片在线播放 | 在线观看国产网站 | 日韩综合在线 | 亚洲欧美视频一区二区 | 成年免费大片黄在线观看一级 | 国产精品国产三级国产aⅴ入口 | 亚洲欧美在线观看 | 亚洲一区影院 | 国产精品美女久久久久久免费 | 91精品国产一区二区三区 | 欧美一区二区三区四区五区无卡码 | 午夜视频网站 | 视频一区在线 | 国产成人精品一区二区三区四区 | 99精品久久久国产一区二区三 | 欧美一区二区三区在线观看 | 国产精品三级 | 亚洲欧美激情视频 | 成人欧美一区二区三区黑人孕妇 | 久久九九99| 欧美精品tv | 国产精品久久久久久久久免费高清 | 久久国产精品视频 | 国产精品久久免费观看 | 精品一区二区三区四区 |