sleep, wakeup, tsleep, return0 – process synchronisation
void sleep(Rendez *r, int (*f)(void*), void *arg)
void wakeup(Rendez *r)
void tsleep(Rendez *r, int (*f)(void*), void *arg, ulong ms)
int return0(void *arg)
A process running in the kernel can use these functions to
synchronise with an interrupt handler or another kernel process.
In particular, they are used by device drivers to wait for an event to be signalled on
receipt of an interrupt.
(In practice, they are most often used indirectly, through
The caller of
and a caller of
structure, to provide a rendezvous point between them
to synchronise on an event.
uses a condition function
that returns true if the event has occurred.
If true, the event has happened and
blocks on the event variable
is called by either a process or an interrupt handler to wake any process
signifying that the corresponding condition is true (the event has occurred).
It has no effect if there is no sleeping process.
is similar to
except that if the condition
is false and the caller does sleep,
and nothing else wakes it within
the system will wake it.
caller must check its environment to decide whether timeout or the event
The timing provided by
is imprecise, but adequate in practice for the normal use of protecting against
lost interrupts and otherwise unresponsive devices or software.
ignores its arguments and returns zero. It is commonly used as
in a call to
to obtain a time delay, using the
structure, for example:
tsleep(&up->sleep, return0, nil, 10);
can be interrupted by
causing a non-local goto through a call to
There can be at most one process waiting on a
and if two processes collide, the system will
(“double sleep ”).
Access to a
must therefore be serialised by some other mechanism, usually
“Process Sleep and Wakeup on a Shared-memory Multiprocessor”,
Plan 9 Programmer’s Manual: Volume 2 .