|
|
front :: data processing thread :: vector size = 0 back :: data processing thread :: vector size = 0 0, 10 front :: data preparation thread :: vector size = 0 front :: data preparation thread :: vector size = 1 front :: data preparation thread :: vector size = 2 front :: data preparation thread :: vector size = 3 front :: data preparation thread :: vector size = 4 front :: data preparation thread :: vector size = 5 front :: data preparation thread :: vector size = 6 front :: data preparation thread :: vector size = 7 front :: data preparation thread :: vector size = 8 front :: data preparation thread :: vector size = 9 10, 10 int_cond = true |
my problems is, how could the int_cond.notify_one() only notify the thread t1 two times? |
No, it's notified just once. The first check is done when it enters 'wait()'. |
The reason why it gets only one notification is that 'data_preparation_thread()' doesn't give up its time slice until it's finished. |
According to your explanation, the boost::condition_variable do not guatantee it would notify the thread when it reach notify_one or notify_all? |
The notify function is non-blocking, so the data_preparation_thread would execute as fast as it could? |
How many times the notify_one would notify data_processing_thread would depend on the schedule of the OS? |
The other question is, I am using a single core cpu to practice concurrency programming what would boost::thread handle the case like this? |