1.\" $OpenBSD: pthread_rwlock_wrlock.3,v 1.9 2010/05/03 20:43:24 jmc 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: May 3 2010 $ 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.Fd #include <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 IMPLEMENTATION NOTES 66To prevent writer starvation, writers are favored over readers. 67.Sh RETURN VALUES 68If successful, the 69.Fn pthread_rwlock_wrlock , 70.Fn pthread_rwlock_timedwrlock , 71and 72.Fn pthread_rwlock_trywrlock 73functions will return zero. 74Otherwise an error number will be returned to indicate the error. 75.Sh ERRORS 76The 77.Fn pthread_rwlock_trywrlock 78function will fail if: 79.Bl -tag -width Er 80.It Bq Er EBUSY 81The calling thread is not able to acquire the lock without blocking. 82.El 83.Pp 84The 85.Fn pthread_rwlock_timedwrlock 86function will fail if: 87.Bl -tag -width Er 88.It Bq Er ETIMEDOUT 89The time specified by 90.Fa abstime 91was reached before the lock could be obtained. 92.El 93.Pp 94The 95.Fn pthread_rwlock_wrlock , 96.Fn pthread_rwlock_timedwrlock , 97and 98.Fn pthread_rwlock_trywrlock 99functions may fail if: 100.Bl -tag -width Er 101.It Bq Er EDEADLK 102The calling thread already owns the read/write lock (for reading 103or writing). 104.It Bq Er EINVAL 105The value specified by 106.Fa lock 107is invalid. 108.It Bq Er ENOMEM 109Insufficient memory exists to initialize the lock (applies to 110statically initialized locks only). 111.El 112.Sh SEE ALSO 113.Xr pthread_rwlock_unlock 3 114.Sh STANDARDS 115The 116.Fn pthread_rwlock_wrlock , 117.Fn pthread_rwlock_timedwrlock , 118and 119.Fn pthread_rwlock_trywrlock 120functions are expected to conform to 121.St -susv2 . 122.Sh HISTORY 123The 124.Fn pthread_rwlock_wrlock 125function first appeared in 126.Fx 3.0 127and 128.Ox 2.5 . 129The 130.Fn pthread_rwlock_timedwrlock 131function first appeared in 132.Ox 4.8 . 133