Unfortunately, such timing errors can still occur when semaphores are used.
To illustrate how, we review the semaphore solution to the critical-section problem.
All processes share a semaphore variable mutex, which is initialized to 1.
Each process must execute wait(mutex) before entering the critical section and signal(mutex) afterward.
If this sequence is not observed, two processes may be in their critical sections simultaneously.
Next, we examine the various difficulties that may result. Note that these difficulties will arise even if a single process is not well behaved.
This situation may be caused by an honest programming error or an uncooperative programmer.