1
我以前知道關鍵部分不能用於進程,因爲它們不是內核對象。但是在現代操作系統中,我看到了兩個可以與進程一起使用的實現。互斥體和臨界區之間的邊界是什麼?
實現與TSL:
enter region:
TSL REGISTER,LOCK | copy lock to register and set lock to 1
CMP REGISTER,#0 | was lock zero?
JNE enter region | if it was not zero, lock was set, so loop
RET | return to caller; critical region entered
leave region:
MOVE LOCK,#0 | store a 0 in lock
RET | return to caller
實現與XCHG:
enter region:
MOVE REGISTER,#1 | put a 1 in the register
XCHG REGISTER,LOCK | swap the contents of the register and lock variable
CMP REGISTER,#0 | was lock zero?
JNE enter region | if it was non zero, lock was set, so loop
RET | return to caller; critical region entered
leave region:
MOVE LOCK,#0 | store a 0 in lock
RET | return to caller
所以無論關鍵部分可用於進程完全取決於實施?互斥體和臨界區之間的邊界在哪裏,我們可以將上面的代碼稱爲臨界區或它是互斥體的代碼?
謝謝。