看板 Grad-ProbAsk 關於我們 聯絡資訊
題目: 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下才能運作嗎? 還是我觀念有誤? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.255.72.148 ※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1510845618.A.FBC.html ※ 編輯: clonsey1314 (111.255.72.148), 11/16/2017 23:21:03
JKLee: B) test-and-set 指令給user用很安全啊 11/16 23:35
shownlin: 因為它拿來設計critical section間一樣是spin lock所以 11/17 00:46
shownlin: 會浪費cpu clock 11/17 00:46
shownlin: 不能work指的是不能滿足臨界區間的條件:mutual exclusi 11/17 00:48
shownlin: on、progress、bounded waiting 11/17 00:48
shownlin: 然候硬體支援未必限定在kernel mode啊,不然user proces 11/17 00:49
shownlin: s需要臨界區間怎麼辦... 11/17 00:49
謝謝J大和s大! 有再把hardware protection的地方再重翻一遍! 再請問一下s大:A的部分, 如果不能work指的是critical section的3大條件, 那test-and-set不是不符合"bounded waiting"嗎? ※ 編輯: clonsey1314 (111.255.66.36), 11/17/2017 01:06:05 ※ 編輯: clonsey1314 (111.255.66.36), 11/17/2017 01:06:46
shownlin: 那邊code你要再看一下,要滿足當然不單靠這個指令 11/17 01:19
shownlin: 還要再加一個waiting的array來實現 11/17 01:20
JKLee: 我覺得A的not work是指P1執行test-and-set(r1)時, 11/17 01:30
JKLee: 不能阻止P2 access r1 11/17 01:31
JKLee: 若要work,P1執行test-and-set時,須強迫暫停其他的processor 11/17 01:34
JKLee: 關於硬體支援,作整數加法也要硬體支援啊(加法器) 11/17 01:36
TMDTMD2487: a)可以work,當然你要良好的使用這個指令才可以 11/17 08:02
TMDTMD2487: b)我猜他是說這個指令可以完全的放在user mode去使用 11/17 08:03
TMDTMD2487: 並實現同步的問題 11/17 08:03
clonsey1314: 謝謝各位大大 11/17 22:50
TWkobe: A:work跟不能用是兩回事,test&set其實還是針對某個cpu 11/22 18:46