diff options
Diffstat (limited to 'man7/sem_overview.7')
-rw-r--r-- | man7/sem_overview.7 | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/man7/sem_overview.7 b/man7/sem_overview.7 index fb9ff1535..9e7afe7eb 100644 --- a/man7/sem_overview.7 +++ b/man7/sem_overview.7 @@ -11,11 +11,13 @@ POSIX semaphores allow processes and threads to synchronize their actions. A semaphore is an integer whose value is never allowed to fall below zero. Two operations can be performed on semaphores: increment the semaphore value by one -.RB ( sem_post (3)); +\%(\c +.MR sem_post 3 ); and decrement the semaphore value by one -.RB ( sem_wait (3)). +\%(\c +.MR sem_wait 3 ). If the value of a semaphore is currently zero, then a -.BR sem_wait (3) +.MR sem_wait 3 operation will block until the value becomes greater than zero. .P POSIX semaphores come in two forms: named semaphores and @@ -39,22 +41,22 @@ followed by one or more characters, none of which are slashes. .\" object in a subdirectory. Two processes can operate on the same named semaphore by passing the same name to -.BR sem_open (3). +.MR sem_open 3 . .IP The -.BR sem_open (3) +.MR sem_open 3 function creates a new named semaphore or opens an existing named semaphore. After the semaphore has been opened, it can be operated on using -.BR sem_post (3) +.MR sem_post 3 and -.BR sem_wait (3). +.MR sem_wait 3 . When a process has finished using the semaphore, it can use -.BR sem_close (3) +.MR sem_close 3 to close the semaphore. When all processes have finished using the semaphore, it can be removed from the system using -.BR sem_unlink (3). +.MR sem_unlink 3 . .TP .B Unnamed semaphores (memory-based semaphores) An unnamed semaphore does not have a name. @@ -67,20 +69,20 @@ A thread-shared semaphore is placed in an area of memory shared between the threads of a process, for example, a global variable. A process-shared semaphore must be placed in a shared memory region (e.g., a System V shared memory segment created using -.BR shmget (2), +.MR shmget 2 , or a POSIX shared memory object built created using -.BR shm_open (3)). +.MR shm_open 3 ). .IP Before being used, an unnamed semaphore must be initialized using -.BR sem_init (3). +.MR sem_init 3 . It can then be operated on using -.BR sem_post (3) +.MR sem_post 3 and -.BR sem_wait (3). +.MR sem_wait 3 . When the semaphore is no longer required, and before the memory in which it is located is deallocated, the semaphore should be destroyed using -.BR sem_destroy (3). +.MR sem_destroy 3 . .P The remainder of this section describes some specific details of the Linux implementation of POSIX semaphores. @@ -93,7 +95,7 @@ a complete implementation of POSIX semaphores is provided. .SS Persistence POSIX named semaphores have kernel persistence: if not removed by -.BR sem_unlink (3), +.MR sem_unlink 3 , a semaphore will exist until the system is shut down. .SS Linking Programs using the POSIX semaphores API must be compiled with @@ -116,8 +118,9 @@ Since Linux 2.6.19, ACLs can be placed on files under this directory, to control object permissions on a per-user and per-group basis. .SH NOTES System V semaphores -.RB ( semget (2), -.BR semop (2), +\%(\c +.MR semget 2 , +.MR semop 2 , etc.) are an older semaphore API. POSIX semaphores provide a simpler, and better designed interface than System V semaphores; @@ -125,15 +128,15 @@ on the other hand POSIX semaphores are less widely available (especially on older systems) than System V semaphores. .SH EXAMPLES An example of the use of various POSIX semaphore functions is shown in -.BR sem_wait (3). +.MR sem_wait 3 . .SH SEE ALSO -.BR sem_close (3), -.BR sem_destroy (3), -.BR sem_getvalue (3), -.BR sem_init (3), -.BR sem_open (3), -.BR sem_post (3), -.BR sem_unlink (3), -.BR sem_wait (3), -.BR pthreads (7), -.BR shm_overview (7) +.MR sem_close 3 , +.MR sem_destroy 3 , +.MR sem_getvalue 3 , +.MR sem_init 3 , +.MR sem_open 3 , +.MR sem_post 3 , +.MR sem_unlink 3 , +.MR sem_wait 3 , +.MR pthreads 7 , +.MR shm_overview 7 |