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

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



NAME    [Toc]    [Back]

     sema, sema_init, sema_destroy, sema_post, sema_wait, sema_timedwait,
     sema_trywait, sema_value -- kernel counting semaphore

SYNOPSIS    [Toc]    [Back]

     #include <sys/types.h>
     #include <sys/lock.h>
     #include <sys/sema.h>

     sema_init(struct sema *sema, int value, const char *description);

     sema_destroy(struct sema *sema);

     sema_post(struct sema *sema);

     sema_wait(struct sema *sema);

     sema_timedwait(struct sema *sema, int timo);

     sema_trywait(struct sema *sema);

     sema_value(struct sema *sema);

DESCRIPTION    [Toc]    [Back]

     Counting semaphores provide a mechanism for synchronizing access to a
     pool of resources.  Unlike mutexes, semaphores do not have the concept of
     an owner, so they can also be useful in situations where one thread needs
     to acquire a resource, and another thread needs to release it.  Each semaphore
 has an integer value associated with it.  Posting (incrementing)
     always succeeds, but waiting (decrementing) can only successfully complete
 if the resulting value of the semaphore is greater than or equal to

     Semaphores should not be used where mutexes and condition variables will
     suffice.  Semaphores are a more complex synchronization mechanism than
     mutexes and condition variables, and are not as efficient.

     Semaphores are created with sema_init(), where sema is a pointer to space
     for a struct sema, value is the initial value of the semaphore, and
     description is a pointer to a null-terminated character string that
     describes the semaphore.  Semaphores are destroyed with sema_destroy().
     A semaphore is posted (incremented) with sema_post().  A semaphore is
     waited on (decremented) with sema_wait(), sema_timedwait(), or
     sema_trywait().  The timo argument to sema_timedwait() specifies the minimum
 time in ticks to wait before returning with failure.	sema_value()
     returns the current value of the semaphore.

     sema_timedwait() and sema_trywait() will return 0 if waiting on the semaphore
 failed; otherwise a non-zero value will be returned to indicate

SEE ALSO    [Toc]    [Back]

     condvar(9), mtx_pool(9), mutex(9), sx(9)

FreeBSD 5.2.1			August 13, 2001 		 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
pixie Tru64 Instruction-counting profiler for optimization and
trimlen IRIX Returns the length of a character argument without counting trailing blanks
len_trim IRIX Returns the length of the character argument without counting trailing blank characters
sem_getvalue OpenBSD get the value of a semaphore
sem_getvalue FreeBSD get the value of a semaphore
semget OpenBSD get semaphore set
sem_getvalue Tru64 Gets the value of a specified semaphore (P1003.1b)
msem_remove Tru64 Remove a semaphore
semget FreeBSD obtain a semaphore id
msem_unlock Tru64 Unlock a semaphore
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service