同一处理器上有两个自旋锁?
两个CPU可以同时持有两个“不同”的自旋锁吗?
那么...这是否意味着:一个单一(单处理器)CPU 不能同时持有两个“不同”的自旋锁?
那么...这是否意味着:单个CPU上的自旋锁数量不能> 1.
PS:“不同”意味着与不同内存资源关联的自旋锁。
有人知道自旋锁内部是如何工作的吗? ...我的意思是,他们在测试集操作期间会冻结总线吗?我用谷歌搜索过但没有绝对的答案。
Can two CPUs hold two "different" spin locks simultaneously at same time?
So...does this mean: a sigle(uniprocessor) CPU cannot hold two "different" spinlocks at the same time?
So...does this mean: the number of spinlocks on a single CPU cannot be > 1.
PS:"different" implying spinlock associated with different memory resources.
Does anybody know how spinlocks work internally? ...I mean, do they freeze bus during test set operations? I have googled but no absolute answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自旋锁或多或少只是一个共享 int,写入是同步的。处理器没有特殊标志。这样你就可以获得多个自旋锁。 (你不应该...)
为了防止单处理器系统锁定,Windows 将 IRQL 提高到
DISPATCH_LEVEL
。处理器只能有一个“线程”在 DISPATCH_LEVEL 上运行,因此在这些系统上同时锁定多个自旋锁是安全的。实现应该是这样的:(不是 100% 正确,并且可能因细节而有所不同)
InterlockedExchange 保证同一内存总线上的所有处理器原子地进行交换。因此它必须锁定内存总线,或者至少强制特定缓存行的唯一所有权。
A spin-lock is more or less only a shared int, to which writes are synchronized. There is no special flag for the processor. So you can acquire more then one spin-lock. (You shouldn't ...)
To prevent uni-processor-system from locking up, windows raises the IRQL to
DISPATCH_LEVEL
. The processor can only have one 'thread' running atDISPATCH_LEVEL
, so locking multiple spin-locks at the same time, is safe on these systems.The implementation should be like this : (not 100% true, and can diverge due to details)
InterlockedExchange
guarantees that the exchange happens atomically for all processors on the same memory bus. So it must lock the memory bus, or at least force sole ownership of the specific cache line.