Data race in C++

时间:2016-08-31 18:14:57

标签: c++11 x86

struct S {
int a;
int b;
};

Size of L1 cache line is equal 64B.

global S s;
Thread1:
s.a = 2;

Thread2: 
s.b = 1;

Is it a data race in C++?

1 个答案:

答案 0 :(得分:2)

No it is not a data race. s.a and s.b are different memory locations . They are accessed and modified independently of each other.

[intro.memory]/3 A memory location is either an object of scalar type or a maximal sequence of adjacent bit-fields all having non-zero width. [ Note: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation. — end note ] Two or more threads of execution (1.10) can update and access separate memory locations without interfering with each other.