开发者

How to write a spinlock without using CAS

开发者 https://www.devze.com 2022-12-28 17:38 出处:网络
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?

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 on开发者_如何学编程e or the other). The platform will not support atomic compare-and-set operations.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号