How to write a spinlock without using CAS

怎甘沉沦 提交于 2019-12-08 03:56:52

问题


Following on from a discussion which got going in the comments of this question.

How would one go about writing a Spinlock without CAS operations?

As the other question states:

The memory ordering model is such that writes will be atomic (if two concurrent threads write a memory location at the same time, the result will be one or the other). The platform will not support atomic compare-and-set operations.


回答1:


Wikipedia's article on spinlock says you'll have to use an algorithm like Peterson's algortihm, which uses another flag to indicate which process's turn it is to enter the critical section (if desired).



来源:https://stackoverflow.com/questions/2754968/how-to-write-a-spinlock-without-using-cas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!