什么是Test-and-Set用于? [英] What is Test-and-Set used for?

查看:447
本文介绍了什么是Test-and-Set用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读测试和设置后维基百科条目,我仍然是留下了一个问题什么是测试和设置?

After reading the Test-and-Set Wikipedia entry, I am still left with the question "What would a Test-and-Set be used for?"

我意识到可以使用它来实现Mutex(如维基百科所述)但是它有什么其他用途?

I realize that you can use it to implement Mutex (as described in wikipedia), but what other uses does it have?

推荐答案

您可以随时在数据写入数据后进行一些工作,确保自从您启动以来,另一个线程没有覆盖目的地。许多锁定/互斥锁算法需要这种形式。

You use it any time you want to write data to memory after doing some work and make sure another thread hasn't overwritten the destination since you started. A lot of lock/mutex-free algorithms take this form.

这篇关于什么是Test-and-Set用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆