I have a blocking queue (it would be very difficult for me to change its implementation), and I want to check that it actually blocks. In particular, methods popshould block if the queue is empty and unlock as soon as it is executed push. See the following pseudo-C ++ 11 code for a test:
BlockingQueue queue;
thread pushThread([]
{
sleep(large_delay);
queue.push();
});
queue.pop();
Obviously, this is not ideal, because it can happen that the entire thread pushThreadexecutes and terminates before it is called pop, even if the delay is large, and the longer the delay, the more I have to wait for the test to end.
How can I correctly verify that it popis executed before it pushis called and will be blocked until pushit returns?