- 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
推薦閱讀
- C及C++程序設計(第4版)
- Implementing VMware Horizon 7(Second Edition)
- Spring 5.0 By Example
- 程序員面試白皮書
- C語言程序設計(第3版)
- Oracle從新手到高手
- SQL for Data Analytics
- 嚴密系統設計:方法、趨勢與挑戰
- C語言實驗指導及習題解析
- 精通Python自動化編程
- Learning Apache Cassandra
- RESTful Java Web Services(Second Edition)
- Python語言科研繪圖與學術圖表繪制從入門到精通
- 平面設計經典案例教程:CorelDRAW X6
- App Inventor 2 Essentials