- Mastering C# Concurrency
- Eugene Agafonov Andrew Koryavchenko
- 185字
- 2021-07-09 21:26:07
Interlocked internals
To understand how interlocked internals work under the hood, we're going to see what machine code is being generated when compiling the Interlocked.Increment
method. If we just run the program in debug mode and look at the disassembly window, we will see the usual method call.
To see what is really going on, we have to enable all optimizations:
- First, we need to build the code in the Release mode in Visual Studio.
- Then, we have to go to Tools | Options | Debugging | General and uncheck the Suppress JIT optimization on module load option.
- Finally, add a
System.Diagnostics.Debugger.Break()
method call to pause the code in debugger.
If everything is set, you will see the following code in the disassembly window:
Interlocked.Increment(ref counter); 00007FFEF22B49AE lea rcx,[rsi+20h] 00007FFEF22B49B2 lock add dword ptr [rcx],1
推薦閱讀
- Node.js 10實(shí)戰(zhàn)
- 重學(xué)Java設(shè)計(jì)模式
- Android底層接口與驅(qū)動(dòng)開發(fā)技術(shù)詳解
- JavaScript入門經(jīng)典
- Android驅(qū)動(dòng)開發(fā)權(quán)威指南
- SQL Server 2008 R2數(shù)據(jù)庫技術(shù)及應(yīng)用(第3版)
- Android Studio Cookbook
- Python Web自動(dòng)化測試設(shè)計(jì)與實(shí)現(xiàn)
- LabVIEW數(shù)據(jù)采集
- HTML5程序開發(fā)范例寶典
- 趣學(xué)數(shù)據(jù)結(jié)構(gòu)
- R High Performance Programming
- 寫給所有人的編程思維
- INSTANT Jsoup How-to
- Magento 2 Development Essentials