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