*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> condvar (9)              



NAME    [Toc]    [Back]

     condvar, cv_init, cv_destroy, cv_wait, cv_wait_sig, cv_timedwait,
     cv_timedwait_sig, cv_signal, cv_broadcast, cv_waitq_remove,
     cv_waitq_empty, cv_wmesg -- kernel condition variable

SYNOPSIS    [Toc]    [Back]

     #include <sys/param.h>
     #include <sys/proc.h>
     #include <sys/condvar.h>

     cv_init(struct cv *cvp, const char *desc);

     cv_destroy(struct cv *cvp);

     cv_wait(struct cv *cvp, struct mtx *mp);

     cv_wait_sig(struct cv *cvp, struct mtx *mp);

     cv_timedwait(struct cv *cvp, struct mtx *mp, int timo);

     cv_timedwait_sig(struct cv *cvp, struct mtx *mp, int timo);

     cv_signal(struct cv *cvp);

     cv_broadcast(struct cv *cvp);

     cv_waitq_remove(struct thread *td);

     cv_waitq_empty(struct cv *cvp);

     const char *
     cv_wmesg(struct cv *cvp);

DESCRIPTION    [Toc]    [Back]

     Condition variables are used in conjunction with mutexes to wait for conditions
 to occur.	Condition variables are created with cv_init(), where
     cvp is a pointer to space for a struct cv, and desc is a pointer to a
     null-terminated character string that describes the condition variable.
     Condition variables are destroyed with cv_destroy().  Threads wait on
     condition variables by calling cv_wait(), cv_wait_sig(), cv_timedwait(),
     or cv_timedwait_sig().  Threads unblock waiters by calling cv_signal() to
     unblock one waiter, or cv_broadcast() to unblock all waiters.
     cv_waitq_remove() removes a waiting thread from a condition variable wait
     queue, if it is on one.  cv_waitq_empty() reports whether there are any
     waiters on cvp.  cv_wmesg() returns the description string of cvp, as set
     by the initial call to cv_init().

     A thread must hold mp before calling cv_wait(), cv_wait_sig(),
     cv_timedwait(), or cv_timedwait_sig().  When a thread waits on a condition,
 mp is atomically released before the thread is blocked, then atomically
 reacquired before the function call returns.  All waiters must pass
     the same mp in conjunction with cvp.  A thread must hold mp while calling
     cv_signal() or cv_broadcast(), even though it isn't passed as an argument.

     When cv_wait(), cv_wait_sig(), cv_timedwait(), and cv_timedwait_sig()
     unblock, their calling threads are made runnable.	cv_timedwait() and
     cv_timedwait_sig() wait for at most timo / HZ seconds before being
     unblocked and returning EWOULDBLOCK; otherwise, they return 0.
     cv_wait_sig() and cv_timedwait_sig() return prematurely with a value of
     EINTR or ERESTART if a signal is caught, or 0 if signaled via cv_signal()
     or cv_broadcast().

RETURN VALUES    [Toc]    [Back]

     If successful, cv_wait_sig(), cv_timedwait(), and cv_timedwait_sig()
     return 0.	Otherwise, a non-zero error code is returned.

     cv_waitq_empty() returns non-zero if there are no threads on the wait
     queue; 0 otherwise.

     cv_wmesg() returns the description string that was passed to cv_init().

ERRORS    [Toc]    [Back]

     cv_wait_sig() and cv_timedwait_sig() will fail if:

     [EINTR]		An unmasked signal was caught.

     [ERESTART] 	A masked signal was caught.

     cv_timedwait() and cv_timedwait_sig() will fail if:

     [EWOULDBLOCK]	Timeout expired.

SEE ALSO    [Toc]    [Back]

     msleep(9), mtx_pool(9), mutex(9), sema(9), sx(9)

FreeBSD 5.2.1		       December 11, 2000		 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
pthread_cond_init OpenBSD create a condition variable
pthread_cond_init Tru64 Initializes a condition variable
tis_cond_init Tru64 Initializes a condition variable
tis_cond_destroy Tru64 Destroys the specified condition variable
pthread_cond_wait FreeBSD wait on a condition variable
pthread_cond_wait OpenBSD wait on a condition variable
pthread_cond_destroy Tru64 Destroys a condition variable
pthread_cond_init FreeBSD create a condition variable
pthread_cond_destroy OpenBSD destroy a condition variable
pthread_cond_destroy FreeBSD destroy a condition variable
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service