題目:
Which one(s) of the following statements adequately describe the test-and-set instruction for process synchronization?
(A) It does not work in multiprocessor environment.
(B) It can all be implemented in the user space, provided that the lock variable is in a shared memory region
(C) It does not waste any CPU cycles when a process cannot acquire a lock
(D) The CPU must guarantee that the test-and-set instruction is an atomic operation.
答案: (B)(D)
請問
A選項: 書上說在multiprocessor系統下用test-and-set效能差, 這個選項錯是因為"只是效能差, 不代表不能用"嗎?
B選項: 硬體的support, 不是要在kernel mode下才能運作嗎? 還是我觀念有誤?
作者:
JKLee (J.K.Lee)
2017-11-16 23:35:00B) test-and-set 指令給user用很安全啊
因為它拿來設計critical section間一樣是spin lock所以會浪費cpu clock不能work指的是不能滿足臨界區間的條件:mutual exclusion、progress、bounded waiting然候硬體支援未必限定在kernel mode啊,不然user process需要臨界區間怎麼辦...那邊code你要再看一下,要滿足當然不單靠這個指令還要再加一個waiting的array來實現
作者:
JKLee (J.K.Lee)
2017-11-17 01:30:00我覺得A的not work是指P1執行test-and-set(r1)時,不能阻止P2 access r1若要work,P1執行test-and-set時,須強迫暫停其他的processor關於硬體支援,作整數加法也要硬體支援啊(加法器)
a)可以work,當然你要良好的使用這個指令才可以b)我猜他是說這個指令可以完全的放在user mode去使用並實現同步的問題
作者:
TWkobe (中華柯比)
2017-11-22 18:46:00A:work跟不能用是兩回事,test&set其實還是針對某個cpu