1.\" $OpenBSD: pthread_rwlock_wrlock.3,v 1.11 2019/02/13 23:54:10 mpi Exp $ 2.\" Copyright (c) 1998 Alex Nash 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.\" $FreeBSD: pthread_rwlock_wrlock.3,v 1.2 1999/08/28 00:03:10 peter Exp $ 27.\" 28.Dd $Mdocdate: February 13 2019 $ 29.Dt PTHREAD_RWLOCK_WRLOCK 3 30.Os 31.Sh NAME 32.Nm pthread_rwlock_wrlock , 33.Nm pthread_rwlock_timedwrlock , 34.Nm pthread_rwlock_trywrlock 35.Nd acquire a read/write lock for writing 36.Sh SYNOPSIS 37.In pthread.h 38.Ft int 39.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock" 40.Ft int 41.Fn pthread_rwlock_timedwrlock "pthread_rwlock_t *lock" "const struct timespec *abstime" 42.Ft int 43.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock" 44.Sh DESCRIPTION 45The 46.Fn pthread_rwlock_wrlock 47function blocks until a write lock can be acquired against 48.Fa lock . 49.Pp 50The 51.Fn pthread_rwlock_timedwrlock 52function performs the same action, 53but will not wait beyond 54.Fa abstime 55to obtain the lock before returning. 56.Pp 57The 58.Fn pthread_rwlock_trywrlock 59function performs the same action as 60.Fn pthread_rwlock_wrlock , 61but does not block if the lock cannot be immediately obtained. 62.Pp 63The results are undefined if the calling thread already holds the 64lock at the time the call is made. 65.Sh RETURN VALUES 66If successful, the 67.Fn pthread_rwlock_wrlock , 68.Fn pthread_rwlock_timedwrlock , 69and 70.Fn pthread_rwlock_trywrlock 71functions will return zero. 72Otherwise an error number will be returned to indicate the error. 73.Sh ERRORS 74The 75.Fn pthread_rwlock_trywrlock 76function will fail if: 77.Bl -tag -width Er 78.It Bq Er EBUSY 79The calling thread is not able to acquire the lock without blocking. 80.El 81.Pp 82The 83.Fn pthread_rwlock_timedwrlock 84function will fail if: 85.Bl -tag -width Er 86.It Bq Er ETIMEDOUT 87The time specified by 88.Fa abstime 89was reached before the lock could be obtained. 90.El 91.Pp 92The 93.Fn pthread_rwlock_wrlock , 94.Fn pthread_rwlock_timedwrlock , 95and 96.Fn pthread_rwlock_trywrlock 97functions may fail if: 98.Bl -tag -width Er 99.It Bq Er EDEADLK 100The calling thread already owns the read/write lock (for reading 101or writing). 102.It Bq Er EINVAL 103The value specified by 104.Fa lock 105is invalid. 106.It Bq Er ENOMEM 107Insufficient memory exists to initialize the lock (applies to 108statically initialized locks only). 109.El 110.Sh SEE ALSO 111.Xr pthread_rwlock_unlock 3 112.Sh STANDARDS 113The 114.Fn pthread_rwlock_wrlock , 115.Fn pthread_rwlock_timedwrlock , 116and 117.Fn pthread_rwlock_trywrlock 118functions are expected to conform to 119.St -susv2 . 120.Sh HISTORY 121The 122.Fn pthread_rwlock_wrlock 123function first appeared in 124.Fx 3.0 125and 126.Ox 2.5 . 127The 128.Fn pthread_rwlock_timedwrlock 129function first appeared in 130.Ox 4.8 . 131