Interlocked类提供对原子操作的轻松访问,例如 fetch and add
和 compare and swap
。
MSDN 说这个类:
Provides atomic operations for variables that are shared by multiple threads.
我的问题是:为什么叫“Interlocked”?它应该意味着什么吗?
最佳答案
http://www.oxforddictionaries.com/definition/english/interlock
A device or mechanism for connecting or coordinating the function of different components: a safety interlock to stop the blades spinning
http://en.wikipedia.org/wiki/Interlock_(engineering)
An interlock is a device used to prevent undesired states in a state machine, which in a general sense can include any electrical, electronic, or mechanical device or system. In most applications an interlock is used to help prevent a machine from harming its operator or damaging itself by stopping the machine when tripped. Household microwave ovens are equipped with interlock switches which disable the magnetron if the door is opened. Similarly household washing machines will interrupt the spin cycle when the lid is open. Interlocks also serve as important safety devices in industrial settings, where they protect employees from devices such as robots, presses, and hammers. While interlocks can be something as sophisticated as curtains of infrared beams and photodetectors, they are often just switches.
这就是它的作用。它可以防止由鲁莽的变量突变引起的不良状态。
关于c# - 名称 "Interlocked"有什么特殊含义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23695512/