semacquire man page on Plan9

Man page or keyword search:  
man Server   549 pages
apropos Keyword Search (all sections)
Output format
Plan9 logo
[printable version]


       semacquire, tsemacquire, semrelease - user level semaphores

       #include <u.h>
       #include <libc.h>

       int semacquire(long *addr, int block);

       int tsemacquire(long *addr, ulong ms);

       long semrelease(long *addr, long count);

       Semacquire,  tsemacquire,  and semrelease facilitate scheduling between
       processes sharing memory.  Processes arrange to share memory  by	 using
       rfork with the RFMEM flag (see fork(2)), segattach(2), or thread(2).

       The  semaphore's	 value	is the integer pointed at by addr.  Semacquire
       atomically waits until the semaphore has	 a  positive  value  and  then
       decrements that value.  If block is zero and the semaphore is not imme‐
       diately available, semacquire returns 0 instead	of  waiting.   Tsemac‐
       quire only waits ms milliseconds for the semaphore to attain a positive
       value and, if available	in  that  time,	 decrements  that  value.   It
       returns	0  otherwise.	Both  functions	 return 1 if the semaphore was
       acquired and -1 on error (e.g., if they were interrupted).   Semrelease
       adds count to the semaphore's value and returns the new value.

       Semacquire  (and	 analogously  for  tsemacquire)	 and semrelease can be
       thought of as efficient, correct replacements for:

	      semacquire(long *addr, int block)
		   while(*addr == 0){
			     return 0;
			     return -1;
		   return 1;

	      semrelease(long *addr, int count)
		   return *addr += count;

       Like rendezvous(2), semacquire, tsemacquire,  and  semrelease  are  not
       typically  used	directly.   Instead,  they  are intended to be used to
       coordinate scheduling in higher-level abstractions such as locks,  ren‐
       dezvous	points,	 and  channels (see lock(2) and thread(2)).  Also like
       rendezvous, semacquire, tsemacquire, and semrelease cannot be  used  to
       coordinate  between threads in a single process.	 Use locks, rendezvous
       points, or channels instead.


       fork(2), lock(2), rendezvous(2), segattach(2), thread(2)

       These functions set errstr.

                             _         _         _ 
                            | |       | |       | |     
                            | |       | |       | |     
                         __ | | __ __ | | __ __ | | __  
                         \ \| |/ / \ \| |/ / \ \| |/ /  
                          \ \ / /   \ \ / /   \ \ / /   
                           \   /     \   /     \   /    
                            \_/       \_/       \_/ 
More information is available in HTML format for server Plan9

List of man pages available for Plan9

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
Vote for polarhome
Free Shell Accounts :: the biggest list on the net