text
stringlengths 0
234
|
---|
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), |
or a posix shared memory object built created using |
.br shm_open (3)). |
.ip |
before being used, an unnamed semaphore must be initialized using |
.br sem_init (3). |
it can then be operated on using |
.br sem_post (3) |
and |
.br 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). |
.pp |
the remainder of this section describes some specific details |
of the linux implementation of posix semaphores. |
.ss versions |
prior to kernel 2.6, linux supported only unnamed, |
thread-shared semaphores. |
on a system with linux 2.6 and a glibc that provides the nptl |
threading implementation, |
a complete implementation of posix semaphores is provided. |
.ss persistence |
posix named semaphores have kernel persistence: |
if not removed by |
.br 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 |
.i cc \-pthread |
to link against the real-time library, |
.ir librt . |
.ss accessing named semaphores via the filesystem |
on linux, named semaphores are created in a virtual filesystem, |
normally mounted under |
.ir /dev/shm , |
with names of the form |
.ir \fbsem.\fpsomename . |
(this is the reason that semaphore names are limited to |
.bi name_max \-4 |
rather than |
.b name_max |
characters.) |
.pp |
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), |
etc.) are an older semaphore api. |
posix semaphores provide a simpler, and better designed interface than |
system v semaphores; |
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). |
.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) |
.sh colophon |
this page is part of release 5.13 of the linux |
.i man-pages |
project. |
a description of the project, |
information about reporting bugs, |
and the latest version of this page, |
can be found at |
\%https://www.kernel.org/doc/man\-pages/. |
.so man7/iso_8859-11.7 |
.\" copyright (c) bruno haible <[email protected]> |
.\" |
.\" %%%license_start(gplv2+_doc_onepara) |
.\" this is free documentation; you can redistribute it and/or |
.\" modify it under the terms of the gnu general public license as |
.\" published by the free software foundation; either version 2 of |
.\" the license, or (at your option) any later version. |
.\" %%%license_end |
.\" |
.\" references consulted: |
.\" gnu glibc-2 source code and manual |
.\" dinkumware c library reference http://www.dinkumware.com/ |
.\" opengroup's single unix specification http://www.unix-systems.org/online.html |
.\" iso/iec 9899:1999 |
Subsets and Splits