lock mutex to protect condition variables