0
比方說我們有一個結構如下─std :: atomic <struct>是否使所有成員都成爲原子?
struct test
{
int a;
int b;
};
我使這個結構的原子變量,並嘗試更新a和b。這些行動是否是原子的?構建一個結構/類是什麼意思?
std::atomic<test> t;
t.a = 10; // is this an atomic operation?
t.b = 20; // is this an atomic operation?
// I understand a and b are not atomic in themselves but I am confused
// as to when you say struct temp is atomic what does it mean?
// does it mean the t instance's this pointer is atomic?
[如何對非基元類型有效地使用std :: atomic <>有可能重複?](https://stackoverflow.com/questions/13885617/how-to-use-stdatomic-effectively-for-non -primitive-types) –
簡短回答:不,正如文檔解釋的那樣,它會獲取並設置整個結構體原子的副本,但不直接訪問其成員。 –
毫無意義,因爲't.a'無效。 'a'是'test'的成員,而不是'atomic' –
LWimsey