- 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
推薦閱讀
- The React Workshop
- Python高效開發(fā)實戰(zhàn):Django、Tornado、Flask、Twisted(第3版)
- Python編程與幾何圖形
- Hands-On Enterprise Automation with Python.
- 從Excel到Python:用Python輕松處理Excel數(shù)據(jù)(第2版)
- Android開發(fā)案例教程與項目實戰(zhàn)(在線實驗+在線自測)
- Learning Laravel's Eloquent
- 學(xué)習(xí)OpenCV 4:基于Python的算法實戰(zhàn)
- The Professional ScrumMaster’s Handbook
- Unity Character Animation with Mecanim
- Java Web從入門到精通(第2版)
- Shopify Application Development
- 例解Python:Python編程快速入門踐行指南
- Offer來了:Java面試核心知識點精講(框架篇)
- Hands-On ROS for Robotics Programming