Lock-free stack - Is this a correct usage of c++11 relaxed atomics? Can it be proven?

后端 未结 3 1335
逝去的感伤
逝去的感伤 2021-02-20 13:36

I\'ve written a container for a very simple piece of data that needs to be synchronized across threads. I want the top performance. I don\'t want to use locks.<

3条回答
  •  温柔的废话
    2021-02-20 14:01

    Leaving to one side the difficulty of implementing the pop operation, I think memory_order_relaxed is inadequate. Before pushing the node, one assumes that some value(s) will be written into to it, which will be read when the node is popped. You need some synchronization mechanism to ensure that the values have actually been written before they are read. memory_order_relaxed is not providing that synchronization... memory_order_acquire/memory_order_release would.

提交回复
热议问题