我发现参考和几个例子在这里,但不明白。
http://en.cppreference.com/w/cpp/atomic/memory_order
谢谢。
Can anyone explain what is std::memory_order in plain English,
我找到的各种记忆顺序最好的“普通英语”解释是Bartoz Milewski的关于松弛原子的文章:http://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering/
后续岗位:http://bartoszmilewski.com/2008/12/23/the-inscrutable-c-memory-model/
但请注意,尽管这些文章是一个很好的介绍,他们在C 11标准之前,并不会告诉你一切你需要知道的安全使用它们。
and how to use them with std::atomic<>?
我最好的建议是:不要。轻松的原子是(可能)C中最棘手和最危险的东西11.坚持std :: atomic< T>与默认内存排序(顺序一致性),直到你真的,真的确保你有一个性能问题,可以通过使用宽松的内存排序解决。
在上面链接的第二篇文章中,Bartoz Milewski得出以下结论:
I had no idea what I was getting myself into when attempting to reason
about C++ weak atomics. The theory behind them is so complex that it’s
borderline unusable. It took three people (Anthony, Hans, and me) and
a modification to the Standard to complete the proof of a relatively
simple algorithm. Imagine doing the same for a lock-free queue based
on weak atomics!
相关文章
- c++ 为什么将memory_order作为std :: atomic函数的运行时参数给出
- c++ std :: function和std :: bind:他们什么时候应该使用它们?
- c - std :: atomic :: compare_exchange与两个memory_order参数一起使用的真实示例
- c - 使用std :: memory_order和三个线程同步谜语
- c++ 如何声明std :: unique_ptr和它的用途是什么?
- c - 什么是std :: atomic?
- c++ 为什么std ::由经验丰富的编码器使用而不是使用命名空间std;?
- c - 如何使用std :: atomic <>
转载注明原文:c,std :: atomic,什么是std :: memory_order和如何使用它们? - 代码日志