2014-02-27 00:03:24 +08:00
|
|
|
@node Inter-Process Communication, Job Control, Processes, Top
|
|
|
|
@c %MENU% All about inter-process communication
|
|
|
|
@chapter Inter-Process Communication
|
|
|
|
@cindex ipc
|
|
|
|
|
|
|
|
This chapter describes the @glibcadj{} inter-process communication primitives.
|
|
|
|
|
|
|
|
@menu
|
|
|
|
* Semaphores:: Support for creating and managing semaphores
|
|
|
|
@end menu
|
|
|
|
|
|
|
|
@node Semaphores
|
|
|
|
@section Semaphores
|
|
|
|
|
2014-02-27 02:39:02 +08:00
|
|
|
@Theglibc{} implements the semaphore APIs as defined in POSIX and
|
2014-02-27 00:03:24 +08:00
|
|
|
System V. Semaphores can be used by multiple processes to coordinate shared
|
|
|
|
resources. The following is a complete list of the semaphore functions provided
|
|
|
|
by @theglibc{}.
|
|
|
|
|
|
|
|
@c Need descriptions for all of these functions.
|
|
|
|
|
|
|
|
@subsection System V Semaphores
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int semctl (int @var{semid}, int @var{semnum}, int @var{cmd})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acunsafe{@acucorrupt{/linux}}}
|
|
|
|
@c syscall(ipc) ok
|
|
|
|
@c
|
|
|
|
@c AC-unsafe because we need to translate the new kernel
|
|
|
|
@c semid_ds buf into the userspace layout. Cancellation
|
|
|
|
@c at that point results in an inconsistent userspace
|
|
|
|
@c semid_ds.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int semget (key_t @var{key}, int @var{nsems}, int @var{semflg})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c syscall(ipc) ok
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int semop (int @var{semid}, struct sembuf *@var{sops}, size_t @var{nsops})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c syscall(ipc) ok
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int semtimedop (int @var{semid}, struct sembuf *@var{sops}, size_t @var{nsops}, const struct timespec *@var{timeout})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c syscall(ipc) ok
|
|
|
|
@end deftypefun
|
|
|
|
|
|
|
|
@subsection POSIX Semaphores
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_init (sem_t *@var{sem}, int @var{pshared}, unsigned int @var{value})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acunsafe{@acucorrupt{}}}
|
|
|
|
@c Does not atomically update sem_t therefore AC-unsafe
|
|
|
|
@c because it can leave sem_t partially initialized.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_destroy (sem_t *@var{sem})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c Function does nothing and is therefore always safe.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun {sem_t *} sem_open (const char *@var{name}, int @var{oflag}, ...)
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@asunsafe{@asuinit{}}@acunsafe{@acuinit{}}}
|
|
|
|
@c pthread_once asuinit
|
|
|
|
@c
|
2023-05-28 00:41:44 +08:00
|
|
|
@c We are AC-Unsafe because we use pthread_once to initialize
|
2014-02-27 00:03:24 +08:00
|
|
|
@c a global variable that holds the location of the mounted
|
|
|
|
@c shmfs on Linux.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_close (sem_t *@var{sem})
|
2014-04-09 05:12:15 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
|
2014-02-27 00:03:24 +08:00
|
|
|
@c lll_lock asulock aculock
|
2014-04-09 05:12:15 +08:00
|
|
|
@c twalk mtsrace{:root}
|
2014-02-27 00:03:24 +08:00
|
|
|
@c
|
|
|
|
@c We are AS-unsafe because we take a non-recursive lock.
|
|
|
|
@c We are AC-unsafe because several internal data structures
|
|
|
|
@c are not updated atomically.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_unlink (const char *@var{name})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@asunsafe{@asuinit{}}@acunsafe{@acucorrupt{}}}
|
|
|
|
@c pthread_once asuinit acucorrupt aculock
|
|
|
|
@c mempcpy acucorrupt
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_wait (sem_t *@var{sem})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acunsafe{@acucorrupt{}}}
|
2022-09-22 22:32:40 +08:00
|
|
|
@c atomic_fetch_add_relaxed (nwaiters) acucorrupt
|
2014-02-27 00:03:24 +08:00
|
|
|
@c
|
|
|
|
@c Given the use atomic operations this function seems
|
|
|
|
@c to be AS-safe. It is AC-unsafe because there is still
|
2022-09-09 21:22:26 +08:00
|
|
|
@c a window between atomic_fetch_add_relaxed and the pthread_push
|
2014-02-27 00:03:24 +08:00
|
|
|
@c of the handler that undoes that operation. A cancellation
|
|
|
|
@c at that point would fail to remove the process from the
|
|
|
|
@c waiters count.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_timedwait (sem_t *@var{sem}, const struct timespec *@var{abstime})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acunsafe{@acucorrupt{}}}
|
|
|
|
@c Same safety issues as sem_wait.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_trywait (sem_t *@var{sem})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c All atomic operations are safe in all contexts.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_post (sem_t *@var{sem})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c Same safety as sem_trywait.
|
|
|
|
@end deftypefun
|
|
|
|
|
2024-10-10 06:32:26 +08:00
|
|
|
@deftypefun int sem_getvalue (sem_t *@var{sem}, int *@var{sval})
|
2014-02-27 00:03:24 +08:00
|
|
|
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
|
|
|
@c Atomic write of a value is safe in all contexts.
|
|
|
|
@end deftypefun
|