TOC
Previous
Next
POSIX Semaphores
How
POSIX semaphores provide three variations:
-
Unnamed semaphores
(sem_init(2),
sem_destroy(2)):
-
Thread shared:
only shared by the threads in a single process;
used for thread synchronisation.
-
Process shared;
used for interprocess synchronization.
-
Semaphore is placed at agreed location in
a region of shared memory.
-
Especially convenient for related
(fork(2)) processes,
since child inherits parent's references to
shared memory regions/segments that parent created.
-
Named semaphores
(sem_open(),
sem_close()):
-
Has a name(!) -- /name
-
Processes can share semaphore by opening same name.
-
Interprocess synchronization.
-
For unrelated processes, a named semaphore is simpler
than setting up an unnamed semaphore in shared memory.
Linux 2.4 only supported unnamed thread-shared semaphores.
A Linux 2.6 system with a glibc that provides
NPTL (glibc 2.3+) supports all flavours of POSIX semaphores.
(C) 2006, Michael Kerrisk