c# - 名称 "Interlocked"有什么特殊含义吗?

标签 c# .net multithreading interlocked

Interlocked类提供对原子操作的轻松访问,例如 fetch and addcompare 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/

相关文章:

java - 无法使用 Thread.interrupt 在 Android 上停止进度条

java - 如何 sleep ()或等待()通过实现可运行接口(interface)创建的线程?

java - 线程阻塞了我的 Android UI

c# - 我们如何在xml中保存特殊符号

c# - 阅读 pop3 电子邮件,为什么不阅读电子邮件?

c# - 编译时的类型或命名空间定义或文件结尾预期问题

c# - 如何将 DataTable.Select() 结果传递给新的 DataTable?

c# - 如何将属性值转换合并到 NHibernate QueryOver .SelectList 中?

c# - 限制多行文本框输入以便打印所有内容

c# - 将库重构为异步,如何避免重蹈覆辙?