Basic spin-lock mutex implementation ordering

后端 未结 3 712
野性不改
野性不改 2020-12-15 06:41

There is a popular spin-lock mutex version which is spreaded across the Internet and which one might encounter in the Anthony Williams book(C++ Concurrency in Action). Here

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 07:13

    As you said, test_and_set is a RMW operation. However, for testing it is only important that the correct value is read. Thus, memory_order_acquire seems sufficient.

    See also table Constants in http://en.cppreference.com/w/cpp/atomic/memory_order

提交回复
热议问题