Reading interlocked variables

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

Assume:

A. C++ under WIN32.

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

10条回答
  •  梦毁少年i
    2020-12-24 02:47

    you should be okay. It's volatile, so the optimizer shouldn't savage you, and it's a 32-bit value so it should be at least approximately atomic. The one possible surprise is if the instruction pipeline can get around that.

    On the other hand, what's the additional cost of using the guarded routines?

提交回复
热议问题