對於單處理器實現的,鎖算法是非常簡單的。如何鎖在多個內核上
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
}
但我們如何在多處理器/多核系統中實現此代碼。如果2個內核/ proc試圖給同一個鎖定不同的進程,該怎麼辦?
只能用原子操作完成,還是需要系統調用(禁用中斷)? – Lee 2016-03-24 19:25:10