[理工] OS 106交大资联 test-and-set

楼主: clonsey1314 (Clonsey)   2017-11-16 23:20:15
题目:
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:00
B) test-and-set 指令给user用很安全啊
作者: shownlin (哈哈阿喔)   2017-11-17 00:46:00
因为它拿来设计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关于硬件支援,作整数加法也要硬件支援啊(加法器)
作者: TMDTMD2487 (ㄚ冰)   2017-11-17 08:02:00
a)可以work,当然你要良好的使用这个指令才可以b)我猜他是说这个指令可以完全的放在user mode去使用并实现同步的问题
楼主: clonsey1314 (Clonsey)   2017-11-17 22:50:00
谢谢各位大大
作者: TWkobe (中华柯比)   2017-11-22 18:46:00
A:work跟不能用是两回事,test&set其实还是针对某个cpu

Links booklink

Contact Us: admin [ a t ] ucptt.com