text
stringlengths 0
234
|
---|
.br tmpnam (3)
|
.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 man2/unimplemented.2
|
.so man3/printf.3
|
.\" copyright (c) 2006 michael kerrisk <mtk.manpages@gmail.com>
|
.\"
|
.\" %%%license_start(verbatim)
|
.\" permission is granted to make and distribute verbatim copies of this
|
.\" manual provided the copyright notice and this permission notice are
|
.\" preserved on all copies.
|
.\"
|
.\" permission is granted to copy and distribute modified versions of this
|
.\" manual under the conditions for verbatim copying, provided that the
|
.\" entire resulting derived work is distributed under the terms of a
|
.\" permission notice identical to this one.
|
.\"
|
.\" since the linux kernel and libraries are constantly changing, this
|
.\" manual page may be incorrect or out-of-date. the author(s) assume no
|
.\" responsibility for errors or omissions, or for damages resulting from
|
.\" the use of the information contained herein. the author(s) may not
|
.\" have taken the same level of care in the production of this manual,
|
.\" which is licensed free of charge, as they might when working
|
.\" professionally.
|
.\"
|
.\" formatted or processed versions of this manual, if unaccompanied by
|
.\" the source, must acknowledge the copyright and authors of this work.
|
.\" %%%license_end
|
.\"
|
.th sem_overview 7 2020-06-09 "linux" "linux programmer's manual"
|
.sh name
|
sem_overview \- overview of posix semaphores
|
.sh description
|
posix semaphores allow processes and threads to synchronize their actions.
|
.pp
|
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));
|
and decrement the semaphore value by one
|
.rb ( sem_wait (3)).
|
if the value of a semaphore is currently zero, then a
|
.br sem_wait (3)
|
operation will block until the value becomes greater than zero.
|
.pp
|
posix semaphores come in two forms: named semaphores and
|
unnamed semaphores.
|
.tp
|
.b named semaphores
|
a named semaphore is identified by a name of the form
|
.ir /somename ;
|
that is, a null-terminated string of up to
|
.bi name_max \-4
|
(i.e., 251) characters consisting of an initial slash,
|
.\" glibc allows the initial slash to be omitted, and makes
|
.\" multiple initial slashes equivalent to a single slash.
|
.\" this differs from the implementation of posix message queues.
|
followed by one or more characters, none of which are slashes.
|
.\" glibc allows subdirectory components in the name, in which
|
.\" case the subdirectory tree must exist under /dev/shm, and
|
.\" the fist subdirectory component must exist as the name
|
.\" sem.name, and all of the subdirectory components must allow the
|
.\" required permissions if a user wants to create a semaphore
|
.\" object in a subdirectory.
|
two processes can operate on the same named semaphore by passing
|
the same name to
|
.br sem_open (3).
|
.ip
|
the
|
.br 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)
|
and
|
.br sem_wait (3).
|
when a process has finished using the semaphore, it can use
|
.br 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).
|
.tp
|
.b unnamed semaphores (memory-based semaphores)
|
an unnamed semaphore does not have a name.
|
instead the semaphore is placed in a region of memory that
|
is shared between multiple threads (a
|
.ir "thread-shared semaphore" )
|
or processes (a
|
.ir "process-shared semaphore" ).
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.