In C/C++, are volatile variables guaranteed to have eventually consistent semantics betwen threads?

前端 未结 6 796
猫巷女王i
猫巷女王i 2020-12-16 02:29

Is there any guarantee by any commonly followed standard (ISO C or C++, or any of the POSIX/SUS specifications) that a variable (perhaps marked volatile), not guarded by a m

6条回答
  •  醉酒成梦
    2020-12-16 03:17

    First off, if it's not marked volatile there is a good chance the compiler may only load it once. So regardless of whether the memory eventually changes, there is no guarantee the compile will set it.

    Since you explicitly say "no mutexes", pthreads doesn't apply.

    Beyond that, since C++ does not have a memory model, it depends on the hardware architecture.

提交回复
热议问题