use*_*851 6 operating-system mutex multicore multiprocessor locks
对于单处理器,锁定算法非常简单。
Lock(threadID) {
Disable Interrupts
If lock is already owned by same thread{
Restore Interrupts
return
}
if lock is free {
make lock busy
set current thread as the owner of the lock
}
else {
add threadID to the lock queue.
}
Restore Interrupts
return
}
Run Code Online (Sandbox Code Playgroud)
但是我们如何在多处理器/多核系统中实现这段代码。如果 2 个内核/进程尝试为不同的进程提供相同的锁怎么办。
| 归档时间: |
|
| 查看次数: |
5222 次 |
| 最近记录: |