A primitive lock is a synchronization primitive that is not owned by a
particular coroutine when locked. A primitive lock is in one of two states,
‘locked’ or ‘unlocked’.

It is created in the unlocked state. It has two basic methods, acquire()
and release(). When the state is unlocked, acquire() changes the state to
locked and returns immediately. When the state is locked, acquire() blocks
until a call to release() in another coroutine changes it to unlocked, then
the acquire() call resets it to locked and returns. The release() method
should only be called in the locked state; it changes the state to unlocked
and returns immediately. If an attempt is made to release an unlocked lock,
a RuntimeError will be raised.

When more than one coroutine is blocked in acquire() waiting for the state
to turn to unlocked, only one coroutine proceeds when a release() call
resets the state to unlocked; first coroutine which is blocked in acquire()
is being processed.

Class implementing event objects. An event manages a flag that can be set to
true with the set() method and reset to false with the clear()
method. The wait() method blocks until the flag is true. The flag is
initially false.

Wake up all coroutines waiting on this condition. This method acts like
notify(), but wakes up all waiting coroutines instead of one. If the
calling coroutine has not acquired the lock when this method is called, a
RuntimeError is raised.

If the calling coroutine has not acquired the lock when this method is
called, a RuntimeError is raised.

This method releases the underlying lock, and then blocks until it is
awakened by a notify() or notify_all() call for the same
condition variable in another coroutine. Once awakened, it re-acquires
the lock and returns True.

A semaphore manages an internal counter which is decremented by each
acquire() call and incremented by each release() call. The
counter can never go below zero; when acquire() finds that it is zero,
it blocks, waiting until some other coroutine calls release().

Semaphores also support the context management protocol.

The optional argument gives the initial value for the internal counter; it
defaults to 1. If the value given is less than 0, ValueError
is raised.

If the internal counter is larger than zero on entry, decrement it by one
and return True immediately. If it is zero on entry, block, waiting
until some other coroutine has called release() to make it larger
than 0, and then return True.