To Mutex or Not To Mutex?

后端 未结 5 2107
眼角桃花
眼角桃花 2020-12-21 00:43

Do I need a mutex if I have only one reader and one writer? The reader takes the next command (food.front()) from the queue and executes a task based on the com

5条回答
  •  星月不相逢
    2020-12-21 01:22

    What happens if the reader sees the size is greater than zero, but the structure isn't yet completely updated?

    That can be avoided by very carefully coding the updates, but the way to make the code resistant to future tampering updates is to use a mutex.

提交回复
热议问题