2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2016 Joyent, Inc.
25 .Nd C11 mutex operations
44 .Fa "const struct timespec *restrict ts"
57 family of functions implement mutual exclusion locks (mutexes) and behave
58 similarly to both POSIX threads and illumos threads; however, they have
59 slightly different call signatures and return values.
60 For more information, see
62 Importantly, they do not allow for inter-process synchronization.
63 .Ss Creating and Destroying Mutexes
66 function initializes the mutex specified by
68 The following types of mutexes are valid and may be specified by the
73 A simple, intra-process mutex.
75 A simple, intra-process mutex, which allows timed locking operations.
76 .It Sy mtx_plain | mtx_recursive
77 An intra-process mutex that may be acquired recursively by the same
79 It must be unlocked an equal number of times that it is locked.
80 .It Sy mtx_timed | mtx_recursive
81 An intra-process mutex that supports timed locking operations and may be
82 acquired recursively by the same thread.
83 It must be unlocked an equal number of times that it is locked.
85 For more information on the different kind of mutexes, see
90 function destroys the mutex pointed to by
92 It is illegal for threads to be blocked waiting for
97 .Ss Locking and Unlocking Mutexes
100 function attempts to lock the mutex
102 When the function returns, it will be the sole owner of the mutex and
105 when it is done, or risk inducing a deadlock in the process.
106 Other threads that make calls to
108 after another thread has successfully completed its call to
111 When they finally return, then they will have obtained the mutex
114 Unless a lock of type
116 was created, a thread calling
118 when it already holds
120 will cause the thread to deadlock.
121 Othewrise, the lock will be successfully taken again.
122 However, a thread must call
124 for each time that it has acquried
129 function will attempt to obtain the mutex pointed to by
135 is locked, then it will not block and wait for
139 to indicate that the lock is currently held.
143 function attempts to obtain the mutex pointed to by
145 If it is unable to obtain it, then it will block for a set amount of
150 is treated as an absolute time in UTC to block until, measured based on
157 function unlocks the mutex pointed to by
159 which allows another thread the opportunity to obtain it.
160 If any threads are actively blocking on the mutex, one of them will obtain it
162 It is an error to call
164 on a mutex which the calling thread does not currently own.
166 Upon successful completion, the function
169 If there was insufficient memory to create the thread,
172 If any other error occurred, it returns
181 If they were unable to successfully complete the operation, they instead
185 Upon successful completion, the
189 If the timeout is reached and the calling thread is unable to obtain the
193 If any other error occurs, then
194 .Sy thrd_error is returned.
196 Upon successful completion, the
200 If the thread was unable to obtain the mutex because another thread owns
203 Otherwise, an error will have occurred and
206 .Sh INTERFACE STABILITY
212 .Xr pthread_mutex_destroy 3C ,
213 .Xr pthread_mutex_init 3C ,
214 .Xr pthread_mutex_lock 3C ,
215 .Xr pthread_mutex_timedlock 3C ,
216 .Xr pthread_mutex_trylock 3C ,
217 .Xr pthread_mutex_unlock 3C ,
218 .Xr threads.h 3HEAD ,