The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Интерактивная система просмотра системных руководств (man-ов)

 ТемаНаборКатегория 
 
 [Cписок руководств | Печать]

msleep_spin (9)
  • >> msleep_spin (9) ( FreeBSD man: Ядро )

  • BSD mandoc
     

    NAME

    msleep
    
     
    msleep_spin
    
     
    pause
    
     
    tsleep
    
     
    wakeup
    
     - wait for events
    
     
    

    SYNOPSIS

       #include <sys/param.h>
       #include <sys/systm.h>
       #include <sys/proc.h>
    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 pause (const char *wmesg int timo);
    int tsleep (void *chan int priority const char *wmesg int timo);
    void wakeup (void *chan);
    void wakeup_one (void *chan);
     

    DESCRIPTION

    The functions tsleep (,);
    msleep (,);
    msleep_spin (,);
    pause (,);
    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 (,);
    msleep_spin (,);
    or pause (.);
    Threads may also wait using one of the locking primitive sleep routines mtx_sleep9, rw_sleep9, or sx_sleep9.

    The parameter Fa chan is an arbitrary address that uniquely identifies the event on which the thread is being put to sleep. All threads sleeping on a single Fa 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 Fa priority specifies a new priority for the thread as well as some optional flags. If the new priority is not 0, then the thread will be made runnable with the specified Fa priority when it resumes. If Fa priority includes the PCATCH flag, signals are checked before and after sleeping, otherwise signals are not checked. If PCATCH is set and a signal needs to be delivered, Er ERESTART is returned if the current system call should be restarted if possible, and Er EINTR is returned if the system call should be interrupted by the signal (return Er EINTR ) .

    The parameter Fa 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 parameter Fa timo specifies a timeout for the sleep. If Fa timo is not 0, then the thread will sleep for at most Fa timo No / Va hz seconds. If the timeout expires, then the sleep function will return Er EWOULDBLOCK .

    Several of the sleep functions including msleep (,);
    msleep_spin (,);
    and the locking primitive sleep routines specify an additional lock parameter. The lock will be released before sleeping and reacquired before the sleep routine returns. If Fa priority includes the PDROP flag, then the lock will not be reacquired before returning. The lock 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. In addition, all of the sleep routines will fully drop the Giant mutex (even if recursed) while the thread is suspended and will reacquire the Giant mutex before the function returns.

    To avoid lost wakeups, either a lock should be used to protect against races, or a timeout should be specified to place an upper bound on the delay due to a lost wakeup. As a result, the tsleep ();
    function should only be invoked with a timeout of 0 when the Giant mutex is held.

    The msleep ();
    function requires that Fa mtx reference a default, i.e. non-spin, mutex. Its use is deprecated in favor of mtx_sleep9 which provides identical behavior.

    The msleep_spin ();
    function requires that Fa mtx reference a spin mutex. The msleep_spin ();
    function does not accept a Fa priority parameter and thus does not support changing the current thread's priority, the PDROP flag, or catching signals via the PCATCH flag.

    The pause ();
    function is a wrapper around tsleep ();
    that suspends execution of the current thread for the indicated timeout. The thread can not be awakened early by signals or calls to wakeup ();
    or wakeup_one (.);

    The wakeup_one ();
    function makes the first thread in the queue that is sleeping on the parameter Fa chan runnable. This reduces the load 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.

    Due to the way it works, the wakeup_one ();
    function requires that only related threads sleep on a specific Fa chan address. It is the programmer's responsibility to choose a unique Fa chan value. The older wakeup ();
    function did not require this, though it was never good practice for threads to share a Fa chan value. When converting from wakeup ();
    to wakeup_one (,);
    pay particular attention to ensure that no other threads wait on the same Fa chan .  

    RETURN VALUES

    If the thread is awakened by a call to wakeup ();
    or wakeup_one (,);
    the msleep (,);
    msleep_spin (,);
    tsleep (,);
    and locking primitive sleep functions return 0. Otherwise, a non-zero error code is returned.  

    ERRORS

    msleep (,);
    msleep_spin (,);
    tsleep (,);
    and the locking primitive sleep functions will fail if:

    Bq Er EINTR
    The PCATCH flag was specified, a signal was caught, and the system call should be interrupted.
    Bq Er ERESTART
    The PCATCH flag was specified, a signal was caught, and the system call should be restarted.
    Bq Er EWOULDBLOCK
    A non-zero timeout was specified and the timeout expired.

     

    SEE ALSO

    ps(1), locking(9), malloc(9), mi_switch9, mtx_sleep9, rw_sleep9, sx_sleep9  

    HISTORY

    The functions sleep ();
    and wakeup ();
    were present in AT&T System v1 . They were probably also present in the preceding PDP-7 version of UNIX They were the basic process synchronization model.

    The tsleep ();
    function appeared in BSD 4.4 and added the parameters Fa wmesg and Fa timo . The sleep ();
    function was removed in Fx 2.2 . 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 pause ();
    function appeared in Fx 7.0 .  

    AUTHORS

    An -nosplit This manual page was written by An J:org Wunsch Aq [email protected] .


     

    Index

    NAME
    SYNOPSIS
    DESCRIPTION
    RETURN VALUES
    ERRORS
    SEE ALSO
    HISTORY
    AUTHORS


    Поиск по тексту MAN-ов: 




    Партнёры:
    PostgresPro
    Inferno Solutions
    Hosting by Hoster.ru
    Хостинг:

    Закладки на сайте
    Проследить за страницей
    Created 1996-2024 by Maxim Chirkov
    Добавить, Поддержать, Вебмастеру