比较和交换与测试和设置
有人可以向我解释一下多线程中上述操作的工作原理和差异吗?
Could someone explain to me the working and differences of above operations in multi-threading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
test-and-set
修改内存位置的内容并作为单个原子操作返回其旧值。compare-and-swap
以原子方式将内存位置的内容与给定值进行比较,仅当它们相同时,才将该内存位置的内容修改为给定值新的价值。差异以粗体标记。
test-and-set
modifies the contents of a memory location and returns its old value as a single atomic operation.compare-and-swap
atomically compares the contents of a memory location to a given value and, only if they are the same, modifies the contents of that memory location to a given new value.The difference marked in bold.
测试和设置对位进行操作,比较和交换对 32 位字段进行操作。
z/TPF 系统倾向于使用测试和设置 (TS) 指令,因为锁定指示符通常是位设置为控制对系统代码关键区域的访问。 测试和设置 (TS) 指令比比较和交换 (CS) 指令需要更少的寄存器,并且需要更少的执行时间,因为只需要设置一个字节。
并且,我从以下位置找到了这些材料: http://www.ibm.com/support/knowledgecenter /SSB23S_1.1.0.13/gtpc3/tasinst.html
您可以通过《现代操作系统,第 2 章》一书了解有关 TSL 的更多信息...
Test and set operates on a bit, compare and swap operates on a 32-bit field.
The z/TPF system favors the use of the test and set (TS) instruction because frequently, lock indicators are bits that are set to control access to critical regions of system code. The test and set (TS) instruction requires fewer registers than the compare and swap (CS) instruction and requires less execution time because only a single byte needs to be set.
and, I found these materials from : http://www.ibm.com/support/knowledgecenter/SSB23S_1.1.0.13/gtpc3/tasinst.html
you can learn more about TSL with the book called "Modern Operating System,Chapter 2"...