xref: /freebsd/share/man/man3/pthread_mutex_timedlock.3 (revision b6413b6db8756c1ecae5e575e6516f811966046f)
1ec2456e2SMike Makonnen.\" Copyright (c) 2003 Michael Telahun Makonnen
2ec2456e2SMike Makonnen.\" All rights reserved.
3ec2456e2SMike Makonnen.\"
4ec2456e2SMike Makonnen.\" Redistribution and use in source and binary forms, with or without
5ec2456e2SMike Makonnen.\" modification, are permitted provided that the following conditions
6ec2456e2SMike Makonnen.\" are met:
7ec2456e2SMike Makonnen.\" 1. Redistributions of source code must retain the above copyright
8ec2456e2SMike Makonnen.\"    notice, this list of conditions and the following disclaimer.
9ec2456e2SMike Makonnen.\" 2. Redistributions in binary form must reproduce the above copyright
10ec2456e2SMike Makonnen.\"    notice, this list of conditions and the following disclaimer in the
11ec2456e2SMike Makonnen.\"    documentation and/or other materials provided with the distribution.
12ec2456e2SMike Makonnen.\"
13ec2456e2SMike Makonnen.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14ec2456e2SMike Makonnen.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15ec2456e2SMike Makonnen.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ec2456e2SMike Makonnen.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17ec2456e2SMike Makonnen.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18ec2456e2SMike Makonnen.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19ec2456e2SMike Makonnen.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20ec2456e2SMike Makonnen.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21ec2456e2SMike Makonnen.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22ec2456e2SMike Makonnen.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23ec2456e2SMike Makonnen.\" SUCH DAMAGE.
24ec2456e2SMike Makonnen.\"
25ec2456e2SMike Makonnen.\" $FreeBSD$
26ec2456e2SMike Makonnen.\"
27*b6413b6dSPedro F. Giffuni.Dd August 17, 2018
28ec2456e2SMike Makonnen.Dt PTHREAD_MUTEX_TIMEDLOCK 3
29ec2456e2SMike Makonnen.Os
30ec2456e2SMike Makonnen.Sh NAME
31ec2456e2SMike Makonnen.Nm pthread_mutex_timedlock
32ec2456e2SMike Makonnen.Nd lock a mutex without blocking indefinitely
33ec2456e2SMike Makonnen.Sh LIBRARY
34fac93adbSRuslan Ermilov.Lb libpthread
35ec2456e2SMike Makonnen.Sh SYNOPSIS
36ec2456e2SMike Makonnen.In pthread.h
37ec2456e2SMike Makonnen.In time.h
38ec2456e2SMike Makonnen.Ft int
39*b6413b6dSPedro F. Giffuni.Fn pthread_mutex_timedlock "pthread_mutex_t *restrict mutex" "const struct timespec *restrict abs_timeout"
40ec2456e2SMike Makonnen.Sh DESCRIPTION
41ec2456e2SMike MakonnenThe
42ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock
43ec2456e2SMike Makonnenfunction will lock
44ec2456e2SMike Makonnen.Fa mutex .
45ec2456e2SMike MakonnenIf it is already locked the calling thread will block until
46ec2456e2SMike Makonnenthe mutex becomes available or
47ec2456e2SMike Makonnenthe timeout,
48ec2456e2SMike Makonnenspecified by abs_timeout,
49ec2456e2SMike Makonnenexpires.
50ec2456e2SMike MakonnenThe time of the timeout is an absolute time and
51ec2456e2SMike Makonnenis not relative to the current time.
52ec2456e2SMike Makonnen.Sh RETURN VALUES
53ec2456e2SMike MakonnenIf successful,
54ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock
55ec2456e2SMike Makonnenwill return zero, otherwise an error number will be returned to
56ec2456e2SMike Makonnenindicate the error.
57ec2456e2SMike Makonnen.Sh ERRORS
58ec2456e2SMike MakonnenThe
59ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock
60ec2456e2SMike Makonnenfunction will fail if:
61ec2456e2SMike Makonnen.Bl -tag -width Er
622a339d9eSKonstantin Belousov.It Bq "Er ENOTRECOVERABLE"
63ec2456e2SMike MakonnenThe
64ec2456e2SMike Makonnen.Fa mutex
65ec2456e2SMike Makonnenwas created with the protocol attribute having the
66ec2456e2SMike Makonnenvalue PTHREAD_PRIO_PROTECT and
67ec2456e2SMike Makonnenthe calling thread's priority is higher than the
68ec2456e2SMike Makonnenmutex's current priority ceiling.
69ec2456e2SMike Makonnen.It Bq Er EINVAL
70ec2456e2SMike MakonnenThe process or thread would have blocked, and
71ec2456e2SMike Makonnen.Fa abs_timeout
72ec2456e2SMike Makonnenspecified a nanosecond value less than zero or
73ec2456e2SMike Makonnengreater than or equal to 1 billion.
74ec2456e2SMike Makonnen.It Bq Er EINVAL
75ec2456e2SMike MakonnenThe
76ec2456e2SMike Makonnen.Fa mutex
77ec2456e2SMike Makonnenparameter is invalid.
78ec2456e2SMike Makonnen.It Bq Er ETIMEDOUT
79ec2456e2SMike MakonnenThe
80ec2456e2SMike Makonnen.Fa mutex
81ec2456e2SMike Makonnencould not be locked before the timeout expired.
82ec2456e2SMike Makonnen.It Bq Er EAGAIN
83ec2456e2SMike MakonnenThe
84ec2456e2SMike Makonnen.Fa mutex
85ec2456e2SMike Makonnencould not be acquired because the
86ec2456e2SMike Makonnenmaximum number of recursive locks for the
87ec2456e2SMike Makonnen.Fa mutex
88ec2456e2SMike Makonnenhas been exceeded.
89ec2456e2SMike Makonnen.It Bq Er EDEADLK
90ec2456e2SMike MakonnenThe current thread already owns the
91ec2456e2SMike Makonnen.Fa mutex .
922a339d9eSKonstantin Belousov.It Bq Er EOWNERDEAD
932a339d9eSKonstantin BelousovThe argument
942a339d9eSKonstantin Belousov.Fa mutex
952a339d9eSKonstantin Belousovpoints to a robust mutex and the previous owning thread terminated
962a339d9eSKonstantin Belousovwhile holding the mutex lock.
972a339d9eSKonstantin BelousovThe lock was granted to the caller and it is up to the new owner
982a339d9eSKonstantin Belousovto make the state consistent.
992a339d9eSKonstantin Belousov.It Bq Er ENOTRECOVERABLE
1002a339d9eSKonstantin BelousovThe state protected by the
1012a339d9eSKonstantin Belousov.Fa mutex
1022a339d9eSKonstantin Belousovis not recoverable.
103ec2456e2SMike Makonnen.El
104ec2456e2SMike Makonnen.Sh SEE ALSO
1052a339d9eSKonstantin Belousov.Xr pthread_mutex_consistent 3 ,
106ec2456e2SMike Makonnen.Xr pthread_mutex_destroy 3 ,
107ec2456e2SMike Makonnen.Xr pthread_mutex_init 3 ,
108ec2456e2SMike Makonnen.Xr pthread_mutex_lock 3 ,
109ec2456e2SMike Makonnen.Xr pthread_mutex_trylock 3 ,
110ec2456e2SMike Makonnen.Xr pthread_mutex_unlock 3
111ec2456e2SMike Makonnen.Sh STANDARDS
112ec2456e2SMike MakonnenThe
113ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock
114ec2456e2SMike Makonnenfunction is expected to conform to
115ec2456e2SMike Makonnen.St -p1003.1-96 .
116