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 pop
should 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 pushThread
executes 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 pop
is executed before it push
is called and will be blocked until push
it returns?