3 .\" Wilfredo Sanchez, wsanchez@apple.com
4 .\" Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
6 .\" @APPLE_LICENSE_HEADER_START@
8 .\" The contents of this file constitute Original Code as defined in and
9 .\" are subject to the Apple Public Source License Version 1.1 (the
10 .\" "License"). You may not use this file except in compliance with the
11 .\" License. Please obtain a copy of the License at
12 .\" http://www.apple.com/publicsource and read it before using this file.
14 .\" This Original Code and all software distributed under the License are
15 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 .\" License for the specific language governing rights and limitations
20 .\" under the License.
22 .\" @APPLE_LICENSE_HEADER_END@
28 .Nm sem_wait, sem_trywait
31 .Fd #include <semaphore.h>
33 .Fn sem_wait "sem_t *sem"
35 .Fn sem_trywait "sem_t *sem"
37 The semaphore referenced by
39 is locked. When calling
41 if the semaphore's value is zero, the calling thread will block until
42 the lock is aquired or until the call is interrupted by a
43 signal. Alternatively, the
45 function will fail if the semaphore is already locked, rather than
46 blocking on the semaphore.
48 If successful (the lock was aquired),
52 will return 0. Otherwise, -1 is returned and
54 is set, and the state of the semaphore is unchanged.
62 The semaphore is already locked.
65 is not a valid semaphore descriptor.
67 A deadlock was detected.
69 The call was interrupted by a signal.
72 Applications may encounter a priority inversion while using
73 semaphores. When a thread is waiting on a semaphore which is about to
74 be posted by a lower-priority thread and the lower-priority thread is
75 preempted by another thread (of medium priority), a priority inversion
76 has occured, and the higher-priority thread will be blocked for an
77 unlimited time period. Programmers using the realtime functionality
78 of the system should take care to avoid priority inversions.
89 are specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995).