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.\" 25*c5fb9d20SKonstantin Belousov.Dd August 7, 2019 26ec2456e2SMike Makonnen.Dt PTHREAD_MUTEX_TIMEDLOCK 3 27ec2456e2SMike Makonnen.Os 28ec2456e2SMike Makonnen.Sh NAME 29ec2456e2SMike Makonnen.Nm pthread_mutex_timedlock 30ec2456e2SMike Makonnen.Nd lock a mutex without blocking indefinitely 31ec2456e2SMike Makonnen.Sh LIBRARY 32fac93adbSRuslan Ermilov.Lb libpthread 33ec2456e2SMike Makonnen.Sh SYNOPSIS 34ec2456e2SMike Makonnen.In pthread.h 35ec2456e2SMike Makonnen.In time.h 36ec2456e2SMike Makonnen.Ft int 37b6413b6dSPedro F. Giffuni.Fn pthread_mutex_timedlock "pthread_mutex_t *restrict mutex" "const struct timespec *restrict abs_timeout" 38ec2456e2SMike Makonnen.Sh DESCRIPTION 39ec2456e2SMike MakonnenThe 40ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock 41ec2456e2SMike Makonnenfunction will lock 42ec2456e2SMike Makonnen.Fa mutex . 43ec2456e2SMike MakonnenIf it is already locked the calling thread will block until 44ec2456e2SMike Makonnenthe mutex becomes available or 45ec2456e2SMike Makonnenthe timeout, 46ec2456e2SMike Makonnenspecified by abs_timeout, 47ec2456e2SMike Makonnenexpires. 48ec2456e2SMike MakonnenThe time of the timeout is an absolute time and 49ec2456e2SMike Makonnenis not relative to the current time. 50ec2456e2SMike Makonnen.Sh RETURN VALUES 51ec2456e2SMike MakonnenIf successful, 52ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock 53ec2456e2SMike Makonnenwill return zero, otherwise an error number will be returned to 54ec2456e2SMike Makonnenindicate the error. 55ec2456e2SMike Makonnen.Sh ERRORS 56ec2456e2SMike MakonnenThe 57ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock 58ec2456e2SMike Makonnenfunction will fail if: 59ec2456e2SMike Makonnen.Bl -tag -width Er 602a339d9eSKonstantin Belousov.It Bq "Er ENOTRECOVERABLE" 61ec2456e2SMike MakonnenThe 62ec2456e2SMike Makonnen.Fa mutex 63ec2456e2SMike Makonnenwas created with the protocol attribute having the 64ec2456e2SMike Makonnenvalue PTHREAD_PRIO_PROTECT and 65ec2456e2SMike Makonnenthe calling thread's priority is higher than the 66ec2456e2SMike Makonnenmutex's current priority ceiling. 67ec2456e2SMike Makonnen.It Bq Er EINVAL 68ec2456e2SMike MakonnenThe process or thread would have blocked, and 69ec2456e2SMike Makonnen.Fa abs_timeout 70ec2456e2SMike Makonnenspecified a nanosecond value less than zero or 71ec2456e2SMike Makonnengreater than or equal to 1 billion. 72ec2456e2SMike Makonnen.It Bq Er EINVAL 73ec2456e2SMike MakonnenThe 74ec2456e2SMike Makonnen.Fa mutex 75ec2456e2SMike Makonnenparameter is invalid. 76ec2456e2SMike Makonnen.It Bq Er ETIMEDOUT 77ec2456e2SMike MakonnenThe 78ec2456e2SMike Makonnen.Fa mutex 79ec2456e2SMike Makonnencould not be locked before the timeout expired. 80ec2456e2SMike Makonnen.It Bq Er EAGAIN 81ec2456e2SMike MakonnenThe 82ec2456e2SMike Makonnen.Fa mutex 83ec2456e2SMike Makonnencould not be acquired because the 84ec2456e2SMike Makonnenmaximum number of recursive locks for the 85ec2456e2SMike Makonnen.Fa mutex 86ec2456e2SMike Makonnenhas been exceeded. 87ec2456e2SMike Makonnen.It Bq Er EDEADLK 88ec2456e2SMike MakonnenThe current thread already owns the 89ec2456e2SMike Makonnen.Fa mutex . 902a339d9eSKonstantin Belousov.It Bq Er EOWNERDEAD 912a339d9eSKonstantin BelousovThe argument 922a339d9eSKonstantin Belousov.Fa mutex 93*c5fb9d20SKonstantin Belousovpoints to a robust mutex and the process containing the previous owning 94*c5fb9d20SKonstantin Belousovthread terminated while holding the mutex lock. 952a339d9eSKonstantin BelousovThe lock was granted to the caller and it is up to the new owner 962a339d9eSKonstantin Belousovto make the state consistent. 972a339d9eSKonstantin Belousov.It Bq Er ENOTRECOVERABLE 982a339d9eSKonstantin BelousovThe state protected by the 992a339d9eSKonstantin Belousov.Fa mutex 1002a339d9eSKonstantin Belousovis not recoverable. 101ec2456e2SMike Makonnen.El 102ec2456e2SMike Makonnen.Sh SEE ALSO 1032a339d9eSKonstantin Belousov.Xr pthread_mutex_consistent 3 , 104ec2456e2SMike Makonnen.Xr pthread_mutex_destroy 3 , 105ec2456e2SMike Makonnen.Xr pthread_mutex_init 3 , 106ec2456e2SMike Makonnen.Xr pthread_mutex_lock 3 , 107ec2456e2SMike Makonnen.Xr pthread_mutex_trylock 3 , 108ec2456e2SMike Makonnen.Xr pthread_mutex_unlock 3 109ec2456e2SMike Makonnen.Sh STANDARDS 110ec2456e2SMike MakonnenThe 111ec2456e2SMike Makonnen.Fn pthread_mutex_timedlock 112ec2456e2SMike Makonnenfunction is expected to conform to 113ec2456e2SMike Makonnen.St -p1003.1-96 . 114