Using volatile long as an atomic

后端 未结 6 1870
感动是毒
感动是毒 2021-01-13 14:29

If I have something like this...

volatile long something_global = 0;

long some_public_func()
{
    return something_global++;
}

Would it b

6条回答
  •  独厮守ぢ
    2021-01-13 15:00

    Volatile just prevents optimizations, but atomicity needs more. In x86, instructions must be preceeded by a LOCK prefix, in MIPS the RMW cycle must be surrounded by an LL/SC construct, ...

提交回复
热议问题