'\" t
-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
.\" 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.
.\"
.\" 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 2010-05-22 "Linux" "Linux Programmer's Manual"
+.TH SEM_OVERVIEW 7 2017-05-03 "Linux" "Linux Programmer's Manual"
.SH NAME
-sem_overview \- Overview of POSIX semaphores
+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
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
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
or processes (a
.IR "process-shared semaphore" ).
A thread-shared semaphore is placed in an area of memory shared
-between by the threads of a process, for example, a global variable.
+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
The remainder of this section describes some specific details
of the Linux implementation of POSIX semaphores.
.SS Versions
-Prior to kernel 2.6, Linux only supported unnamed,
+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 semaphore will exist until the system is shut down.
.SS Linking
Programs using the POSIX semaphores API must be compiled with
-.I cc \-lrt
+.I cc \-pthread
to link against the real-time library,
.IR librt .
-.SS Accessing named semaphores via the file system
-On Linux, named semaphores are created in a virtual file system,
+.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
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 "CONFORMING TO"
-POSIX.1-2001.
.SH NOTES
System V semaphores
.RB ( semget (2),
.SH EXAMPLE
An example of the use of various POSIX semaphore functions is shown in
.BR sem_wait (3).
-.SH "SEE ALSO"
+.SH SEE ALSO
.BR sem_close (3),
.BR sem_destroy (3),
.BR sem_getvalue (3),
.BR sem_post (3),
.BR sem_unlink (3),
.BR sem_wait (3),
-.BR pthreads (7)
+.BR pthreads (7),
+.BR shm_overview (7)