The getchar code above has a major flaw – the thread holding the mutex will continue to spin on the flag test until it succeeds. Ideally, we need a mechanism to allow the waiting thread to sleep until space is available. With peripherals such as UARTs we have already seen that interrupt code can handle the actual changes in hardware status.