凉拌八爪鱼
理解MIPS指令集中的ll(loadlinked)和sc(storeconditional)指令
关于MIPS指令集的ll(load linked)和sc(store conditional)指令,课本上的叙述实在不好理解(于我)驾照扣分
所以找了⼀个⽐较好理解的版本记录下来。
婚假怎么休
塔伊普Q:What is ll and sc in mips?
如何停用朋友圈
A:Load linked (LL) and store conditional (SC) instructions are a way to achieve atomic memory >updates in shared memory multiprocessor systems, without locking memory locations for >exclusive access by one processor.
李秘书The idea is that you u LL to load the value stored at a memory location into a register, modify >it however you like there, and subquently write it back to the same place using SC. SC will only >overwrite the value in memory with your modified one if no other processor has altered it while >you were working on the copy in the register. It has the side-effect of tting a status flag to >indicate whether or not it was successful.
五指山图片When the updated value is successfully stored, a thread can trust that its read-modify-write >quence was completed without interference from other threads. On a failure, it is up to the >program to decide
whether to give up or reload the address and try again, but at least it doesn’t >produce an undetected Race condition.
英⽂部分转⾃
拙劣的翻译:
ll和sc指令是⼀种在多处理器系统中实现共享内存的原⼦操作的⽅法,且不需要为了让⼀个处理器独占它⽽锁定它。
意思是,你⽤ll指令读取⼀个内存中的数据并存到⼀个寄存器,然后在寄存器修改(或不)这个值,随后⽤sc指令将它写⼊到同样的(原来的)位置。⽽sc指令只在你修改寄存器中的值的期间,没有任何⼀个处理器改变它内存中的值 这种情况下,将值写⼊。它同时需要(的副作⽤是)设置⼀个指⽰状态的变量来表明是否成功写⼊。(成功为1,失败为0)
龙嘴大铜壶当新的值成功地被写⼊了,那么可以认为这个线程在没有别的线程⼲涉的情况下完成了(⼀个值的)读-改-写过程。如果失败了,接下来就取决于程序是要放弃这个操作还是再试⼀次了,不过⾄少它(ll&sc)不会⽣成⼀个隐性的(不被察觉的)竞争危害。