Conditional Variable vs Semaphore
问题 When should one use a semaphore and when should one use a conditional variable (CondVar) ? 回答1: Locks are used for mutual exclusion. When you want to ensure that a piece of code is atomic, put a lock around it. You could theoretically use a binary semaphore to do this, but that's a special case. Semaphores and condition variables build on top of the mutual exclusion provide by locks and are used for providing synchronized access to shared resources. They can be used for similar purposes. A