of an item is inexplicably delayed in the worst casethe whole program will hang due to the loss of an event signal for these types of problemsyou are better off using condition variables condition variables condition variable is synchronization primitivebuilt on top of another lock that' used when thread is interested in particular change of state or event occurring typical use is producer-consumer problem where one thread is producing data to be consumed by another thread new condition instance is created using the following constructorcondition([lock]creates new condition variable lock is an optional lock or rlock instance if not supplieda new rlock instance is created for use with the condition variable condition variablecvsupports the following methodscv acquire(*argsacquires the underlying lock this method calls the corresponding acquire(*argsmethod on the underlying lock and returns the result cv release(releases the underlying lock this method calls the corresponding release(method on the underlying lock cv wait([timeout]waits until notified or until timeout occurs this method is called after the calling thread has already acquired the lock when calledthe underlying lock is releasedand the thread goes to sleep until it' awakened by notify(or notifyall(call performed on the condition variable by another thread once awakenedthe thread reacquires the lock and the method returns timeout is floating-point number in seconds if this time expiresthe thread is awakenedthe lock reacquiredand control returned cv notify([ ]wakes up one or more threads waiting on this condition variable this method is called only after the calling thread has acquired the lockand it does nothing if no threads are waiting specifies the number of threads to awaken and defaults to awakened threads don' return from the wait(call until they can reacquire the lock cv notify_all(wakes up all threads waiting on this condition this method is called notifyall(in older code here is an example that provides template of using condition variablescv threading condition(def producer()while truecv acquire(produce_item(cv notify(cv release( lib fl ff