The program is easy to block.
I add some output in enqueue function and thread.
This is the output when the program block.
We can see, when notify_one() was call, two threads were blocking on condition.wait() and one thread was in calculating and one thread was waiting for mtx.lock().
I can't understand why the main thread will block.
When you change the example.cpp as follows(1.more than 1000 loop times and 2.delete cout in work function):
The program is easy to block. I add some output in enqueue function and thread. This is the output when the program block.
We can see, when notify_one() was call, two threads were blocking on condition.wait() and one thread was in calculating and one thread was waiting for mtx.lock().
I can't understand why the main thread will block.