GSP
Quick Navigator

Search Site

Linux VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  - SLEEP (9)

NAME

msleep, msleep_spin, tsleep, wakeup - wait for events

CONTENTS

Synopsis
Description
Return Values
See Also
History
Authors

SYNOPSIS


.In sys/param.h
.In sys/systm.h
.In sys/proc.h int tsleep void *chan int priority const char *wmesg int timo int msleep void *chan struct mtx *mtx int priority const char *wmesg int timo int msleep_spin void *chan struct mtx *mtx const char *wmesg int timo void wakeup void *chan void wakeup_one void *chan

DESCRIPTION

The functions tsleep, msleep, msleep_spin, wakeup, and wakeup_one handle event-based thread blocking. If a thread must wait for an external event, it is put to sleep by tsleep, msleep, or msleep_spin. The parameter chan is an arbitrary address that uniquely identifies the event on which the thread is being asleep. All threads sleeping on a single chan are woken up later by wakeup, often called from inside an interrupt routine, to indicate that the resource the thread was blocking on is available now.

The parameter wmesg is a string describing the sleep condition for tools like ps(1). Due to the limited space of those programs to display arbitrary strings, this message should not be longer than 6 characters.

The wakeup_one function is used to make the first thread in the queue that is sleeping on the parameter chan runnable. This can prevent the system from becoming saturated when a large number of threads are sleeping on the same address, but only one of them can actually do any useful work when made runnable.

The msleep function is the general sleep call. It suspends the current thread until a wakeup is performed on the specified identifier. The mtx parameter is a mutex which will be released before sleeping and reacquired before msleep returns. If priority includes the PDROP flag, the mtx parameter will not be reacquired before returning. The mutex is used to ensure that a condition can be checked atomically, and that the current thread can be suspended without missing a change to the condition, or an associated wakeup. If priority is not 0, then the thread will be made runnable with the specified priority when it resumes. If timo is not 0, then the thread will sleep for at most timo / hz seconds. If the Giant lock is not held and mtx is NULL, then timo must be non-zero. If priority includes the PCATCH flag, signals are checked before and after sleeping, otherwise signals are not checked. The msleep function returns 0 if awakened, EWOULDBLOCK if the timeout expires. If PCATCH is set and a signal needs to be delivered, ERESTART is returned if the current system call should be restarted if possible, and EINTR is returned if the system call should be interrupted by the signal (return EINTR).

The tsleep function is a variation on msleep. It is identical to invoking msleep with a NULL mtx parameter.

The msleep_spin function is another variation on msleep. This function accepts a spin mutex rather than a default mutex for its mtx parameter. It is also more limited in that it does not accept a priority parameter. Thus, it will not change the priority of a sleeping thread, and it does not support the PDROP and PCATCH flags.

RETURN VALUES

See above.

SEE ALSO

ps(1), malloc(9), mi_switch(9)

HISTORY

The sleep/wakeup thread synchronization mechanism is very old. It appeared in a very early version of Unix .

The tsleep function appeared in BSD 4.4 . The wakeup_one function appeared in
.Fx 2.2 . The msleep function appeared in
.Fx 5.0 , and the msleep_spin function appeared in
.Fx 6.2 .

The sleep function used to be the traditional form. It did not let you specify a timeout or a wmesg, hence it was discontinued.

AUTHORS


.An -nosplit This manual page was written by
.An J\(:org Wunsch Aq joerg@FreeBSD.org .
Search for    or go to Top of page |  Section 9 |  Main Index


April 17, 2006 SLEEP (9)

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.