Reading interlocked variables

后端 未结 10 1094
鱼传尺愫
鱼传尺愫 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 02:47

    The Interlocked* functions prevent two different processors from accessing the same piece of memory. In a single processor system you are going to be ok. If you have a dual-core system where you have threads on different cores both accessing this value, you might have problems doing what you think is atomic without the Interlocked*.

提交回复
热议问题