简体   繁体   English

使用自旋锁锁定在不同线程中同时使用的变量?

[英]Using spin lock to lock a variable being concurrently used in a different thread?

Say you call spin_lock(&key) and key is having some type of operation being performed on it in a different thread at the same time.假设您调用 spin_lock(&key) 并且 key 同时在不同的线程中对其执行某种类型的操作。 Is the other thread being paused/interrupted?另一个线程是否被暂停/中断?

What happens to the other thread that's in the middle of altering or using key?正在更改或使用密钥的另一个线程会发生什么? Such as if the thread was calling copy_to_user(key), copy_from_user(key) or kmallocing/kfreeing key?例如,如果线程正在调用 copy_to_user(key)、copy_from_user(key) 或 kmallocing/kfreeing 密钥?

Don't know specifically about Linux kernel spin_lock() , but in practically all programming environments, mutex locking is advisory .不具体了解Linux 内核spin_lock() ,但实际上在所有编程环境中,互斥锁都是建议性的 That means, locking a lock never prevents anything except, it prevents other threads from locking the same lock at the same time.这意味着,锁定一个锁永远不会阻止任何事情,除了它可以防止其他线程同时锁定同一个锁。 If you want to use a lock to protect some variable or data structure, then it's entirely the programmer's responsibility to ensure that no code anywhere in the system ever accesses the data except when the lock is locked.如果您想使用锁来保护某些变量或数据结构,那么确保系统中任何地方的代码都不会访问数据,除非锁被锁定,这完全是程序员的责任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM