从多个线程对double进行+ =的结果

考虑以下代码:

void add(double& a, double b) {
    a += b;
}

which according to godbolt compiles on a Skylake to:

add(double&, double):
  vaddsd xmm0, xmm0, QWORD PTR [rdi]
  vmovsd QWORD PTR [rdi], xmm0
  ret

If I call add(a, 1.23) and add(a, 2.34) from different threads (for the same variable a), will a definitely end up as either a+1.23, a+2.34, or a+1.23+2.34?

That is, will one of these results definitely happen given this assembly, and a will not end up in some other state?

评论