我发现下面的代码,该出把永远是: std::atomic<A> is lock free? false
std::atomic<B> is lock free? true
这是代码: struct A { int a[100]; };
struct B { int x, y; };
int main()
{
std::cout << std::boolalpha
考虑我有两个原子布尔值如下。 private:
std::atomic_bool x;
std::atomic_bool y;
可以说下面的操作是原子的吗?还是必须使用lock_guard才能确保将它们分配在一起? x = y = true; // are two bools assigned together atomically?
也考虑在另一个线程我想读这些布尔值