久久久久久久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 ()?環形?)
主站蜘蛛池模板: 亚洲国产精品人人爽夜夜爽 | 成人做爰69片免费观看 | 一级a性色生活片久久毛片波多野 | 国产精品久久久久久久久久久久久 | 欧美a级成人淫片免费看 | 中国一级大毛片 | 色综合99 | 欧美成人精品一区二区三区 | 精品久久精品 | 成人影院免费视频 | www.玖玖玖| www.yw193.com| 久久精品国内 | 国产一区二区三区在线 | 在线中文字幕视频 | 九九热九九 | 国产精品久久久久一区二区三区 | 欧美成人h版在线观看 | www.中文字幕.com | 日韩欧美在线观看 | 日韩欧美成人一区二区三区 | 久草综合在线 | 欧美一级α片 | 国产精品免费一区二区三区四区 | 日韩欧美中文在线 | 欧美成人在线免费 | 中文字幕一区二区三区四区五区 | 男人天堂网av | 国产精品视频一区二区三区四区国 | 偷派自拍 | 国产一级视频在线观看 | 日韩视频在线免费观看 | 玖玖视频网 | 在线观看www | 欧美日韩精品一区二区三区四区 | 日本三级视频 | 亚洲中字在线 | 日本黄色免费视频 | 国产高清不卡 | 1000部精品久久久久久久久 | 亚洲福利一区 |