Why do I need to acquire a lock to modify a shared “atomic” variable before notifying condition_variable

后端 未结 2 1928
忘了有多久
忘了有多久 2020-12-06 06:22

Accoding to cppreference.com:

The thread that intends to modify the variable has to

  1. acquire a std::mutex (typically via std::lock_
2条回答
  •  隐瞒了意图╮
    2020-12-06 06:45

    Found a very good explanation about this issue in another thread. Take a loot at

    Questions where asked below about race conditions.

    If the data being communicated is atomic, can't we do without the mutex on the "send" side?

    at the end.

提交回复
热议问题