Reading interlocked variables

后端 未结 10 1119
鱼传尺愫
鱼传尺愫 2020-12-24 02:23

Assume:

A. C++ under WIN32.

B. A properly aligned volatile integer incremented and decremented using InterlockedIncrement() and Interlocke

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 03:08

    32-bit read operations are already atomic on some 32-bit systems (Intel spec says these operations are atomic, but there's no guarantee that this will be true on other x86-compatible platforms). So you shouldn't use this for threads synchronization.

    If you need a flag some sort you should consider using Event object and WaitForSingleObject function for that purpose.

提交回复
热议问题