The following sections discuss when to use a mutex and when to use a condition variable and the use of mutexes to prevent two common problems: race conditions and deadlocks. This section also discusses why you should signal a condition variable with the associated mutex locked.