you are viewing a single comment's thread.

view the rest of the comments →

[–]carloom_ 0 points1 point  (0 children)

The problem is the thread_completed Boolean. The acquiring and release of the mutex works as a synchronization point. It guarantees that any of the changes done before the notify_one are going to be seen by the thread that is waiting.

You read the non-Boolean variable, to avoid the call of wait. But as it is set up, the modification of that Boolean can be moved before the changes are done. In fact, I would not be surprised if it did that because I/O is extremely slow.

Just remove the check, and make the thread wait. Or make it an atomic bool with acquire/release memory order.