Explain how a condition variable should be used with a predicate and a mutex.