Race conditions are usually difficult to discover, because they occur intermittently. For example, if thread A takes a lock and updates the counter, it leaves memory X with a value of 2. A releases the lock, thread B takes the lock and updates the counter, taking 2 as its initial value for X and incrementing it to 3, the expected result. See Using Mutexes for more information about mutexes. Waiting for Threads Condition variables allow threads to block until some event or condition has occurred.
Boolean predicates indicate whether the program has satisfied a condition variable.
The complexity of a condition variable predicate is defined by the programmer. A condition can be signaled by any thread to either one or all waiting threads. See Using Condition Variables to get more information. When a thread is terminated, its storage may not be reclaimed, depending on an attribute of the thread. Such threads can be joined by other threads and return information to them.