Multiple Consumers Example using the Test&Set Instruction P: Test& Set(mutex), Temp if (temp!=0) goto P Load Rhead,(head) spin: Load Rtail,(tail) Critical if Rhead==Rtai goto spin Section Load R,(rhead) Rhead=Rhead+1 Store(head), Rhead V: Store(mutex),0 process(r) 其他原子的read- modify- write指令(SWap, Fetch&Ad,etc.)也能实现P(s)和V(S)操作 2021/2/11 计算机体系结构Multiple Consumers Example using the Test&Set Instruction 2021/2/11 计算机体系结构 28 Critical Section P: Test&Set (mutex),Rtemp if (Rtemp!=0) goto P Load Rhead, (head) spin: Load Rtail, (tail) if Rhead==Rtail goto spin Load R, (Rhead) Rhead=Rhead+1 Store (head), Rhead V: Store (mutex),0 process(R) 其他原子的read-modify-write 指令 (Swap, Fetch&Add, etc.) 也能实现 P(s)和 V(s)操作