use condition variables to ensure blocking