How to provide a sequence of interleaving threads to show that a code breaks and doesn't provide perfect synchronization?

前端 未结 2 1480
余生分开走
余生分开走 2021-01-27 16:38

I know what the following code does and I know why it is a broken code for synchronization as it has only one conditional variable while we need two but I don\'t know how to pro

2条回答
  •  伪装坚强ぢ
    2021-01-27 17:19

    "cond" is not initialized. You have a race condition between consumer and producer. If any of the "while" condition becomes true, they will result in infinite loop as no instruction changes the values of "count" in the "while" scopes (both).

提交回复
热议问题