Do I need a memory barrier for a change notification flag between threads?

前端 未结 3 2075
一生所求
一生所求 2021-02-06 11:54

I need a very fast (in the sense \"low cost for reader\", not \"low latency\") change notification mechanism between threads in order to update a read cache:

The

3条回答
  •  野的像风
    2021-02-06 12:17

    You do have to use a memory fence here. Without the fence, there is no guarantee updates will be ever seen on the other thread. In C++03 you have the option of either using platform-specific ASM code (mfence on Intel, no idea about ARM) or use OS-provided atomic set/get functions.

提交回复
热议问题