[英]Can there be a difference between explicit operator= call and = operator?
[英]What is the difference between explicit atomic load/store and usual operator= and operator T?
考慮以下兩種變體:
std::atomic<int> a;
a = 1;
int b = a;
和
std::atomic<int> a;
a.store(1);
int b = a.load();
我從文檔中看到第二個是完全原子的,但我不明白何時應該使用哪個以及什么是細節上的差異。
這兩個例子是等價的; operator=
和operator T
分別等同於使用memory_order
參數的默認值調用store
和load
。
如果您對該默認值memory_order_seq_cst
感到滿意,那么每次訪問都充當內存柵欄,那么請使用看起來更漂亮的內容。 如果要指定其他值,則需要使用這些函數,因為運算符不能接受第二個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.