1c0e36632SAlexander Langer.\" Copyright (c) 1998 Alex Nash 2c0e36632SAlexander Langer.\" All rights reserved. 3c0e36632SAlexander Langer.\" 4c0e36632SAlexander Langer.\" Redistribution and use in source and binary forms, with or without 5c0e36632SAlexander Langer.\" modification, are permitted provided that the following conditions 6c0e36632SAlexander Langer.\" are met: 7c0e36632SAlexander Langer.\" 1. Redistributions of source code must retain the above copyright 8c0e36632SAlexander Langer.\" notice, this list of conditions and the following disclaimer. 9c0e36632SAlexander Langer.\" 2. Redistributions in binary form must reproduce the above copyright 10c0e36632SAlexander Langer.\" notice, this list of conditions and the following disclaimer in the 11c0e36632SAlexander Langer.\" documentation and/or other materials provided with the distribution. 12c0e36632SAlexander Langer.\" 13c0e36632SAlexander Langer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14c0e36632SAlexander Langer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15c0e36632SAlexander Langer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16c0e36632SAlexander Langer.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17c0e36632SAlexander Langer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18c0e36632SAlexander Langer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19c0e36632SAlexander Langer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20c0e36632SAlexander Langer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21c0e36632SAlexander Langer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22c0e36632SAlexander Langer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23c0e36632SAlexander Langer.\" SUCH DAMAGE. 24c0e36632SAlexander Langer.\" 25c0e36632SAlexander Langer.Dd August 4, 1998 26c0e36632SAlexander Langer.Dt PTHREAD_RWLOCK_WRLOCK 3 27c0e36632SAlexander Langer.Os 28c0e36632SAlexander Langer.Sh NAME 29c0e36632SAlexander Langer.Nm pthread_rwlock_wrlock , 30c0e36632SAlexander Langer.Nm pthread_rwlock_trywrlock 31c0e36632SAlexander Langer.Nd acquire a read/write lock for writing 32d8a78688SAlexey Zelkin.Sh LIBRARY 33ec7452f1SRuslan Ermilov.Lb libpthread 34c0e36632SAlexander Langer.Sh SYNOPSIS 3532eef9aeSRuslan Ermilov.In pthread.h 36c0e36632SAlexander Langer.Ft int 37c0e36632SAlexander Langer.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock" 38c0e36632SAlexander Langer.Ft int 39c0e36632SAlexander Langer.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock" 40c0e36632SAlexander Langer.Sh DESCRIPTION 41c0e36632SAlexander LangerThe 42c0e36632SAlexander Langer.Fn pthread_rwlock_wrlock 43c0e36632SAlexander Langerfunction blocks until a write lock can be acquired against 44c0e36632SAlexander Langer.Fa lock . 45c0e36632SAlexander LangerThe 46c0e36632SAlexander Langer.Fn pthread_rwlock_trywrlock 47c0e36632SAlexander Langerfunction performs the same action, but does not block if the lock 48c0e36632SAlexander Langercannot be immediately obtained. 49c0e36632SAlexander Langer.Pp 50c0e36632SAlexander LangerThe results are undefined if the calling thread already holds the 51c0e36632SAlexander Langerlock at the time the call is made. 52c0e36632SAlexander Langer.Sh IMPLEMENTATION NOTES 53c0e36632SAlexander LangerTo prevent writer starvation, writers are favored over readers. 54c0e36632SAlexander Langer.Sh RETURN VALUES 55c0e36632SAlexander LangerIf successful, the 56c0e36632SAlexander Langer.Fn pthread_rwlock_wrlock 57c0e36632SAlexander Langerand 58c0e36632SAlexander Langer.Fn pthread_rwlock_trywrlock 595203edcdSRuslan Ermilovfunctions will return zero. 605203edcdSRuslan ErmilovOtherwise an error number will be returned 61c0e36632SAlexander Langerto indicate the error. 62c0e36632SAlexander Langer.Sh ERRORS 63c0e36632SAlexander LangerThe 64c0e36632SAlexander Langer.Fn pthread_rwlock_trywrlock 65c0e36632SAlexander Langerfunction will fail if: 66c0e36632SAlexander Langer.Bl -tag -width Er 67c0e36632SAlexander Langer.It Bq Er EBUSY 68c0e36632SAlexander LangerThe calling thread is not able to acquire the lock without blocking. 69c0e36632SAlexander Langer.El 70c0e36632SAlexander Langer.Pp 71c0e36632SAlexander LangerThe 72c0e36632SAlexander Langer.Fn pthread_rwlock_wrlock 73c0e36632SAlexander Langerand 74c0e36632SAlexander Langer.Fn pthread_rwlock_trywrlock 75c0e36632SAlexander Langerfunctions may fail if: 76c0e36632SAlexander Langer.Bl -tag -width Er 77c0e36632SAlexander Langer.It Bq Er EDEADLK 78c0e36632SAlexander LangerThe calling thread already owns the read/write lock (for reading 79c0e36632SAlexander Langeror writing). 80c0e36632SAlexander Langer.It Bq Er EINVAL 81c0e36632SAlexander LangerThe value specified by 82c0e36632SAlexander Langer.Fa lock 83c0e36632SAlexander Langeris invalid. 84c0e36632SAlexander Langer.It Bq Er ENOMEM 85c0e36632SAlexander LangerInsufficient memory exists to initialize the lock (applies to 86c0e36632SAlexander Langerstatically initialized locks only). 87c0e36632SAlexander Langer.El 889cbda590SRuslan Ermilov.Sh SEE ALSO 899cbda590SRuslan Ermilov.Xr pthread_rwlock_init 3 , 909cbda590SRuslan Ermilov.Xr pthread_rwlock_rdlock 3 , 919cbda590SRuslan Ermilov.Xr pthread_rwlock_tryrdlock 3 , 929cbda590SRuslan Ermilov.Xr pthread_rwlock_unlock 3 939cbda590SRuslan Ermilov.Sh STANDARDS 949cbda590SRuslan ErmilovThe 959cbda590SRuslan Ermilov.Fn pthread_rwlock_wrlock 969cbda590SRuslan Ermilovand 979cbda590SRuslan Ermilov.Fn pthread_rwlock_trywrlock 989cbda590SRuslan Ermilovfunctions are expected to conform to 999cbda590SRuslan Ermilov.St -susv2 . 100c0e36632SAlexander Langer.Sh HISTORY 101c0e36632SAlexander LangerThe 102c0e36632SAlexander Langer.Fn pthread_rwlock_wrlock 103c0e36632SAlexander Langerfunction first appeared in 104c0e36632SAlexander Langer.Fx 3.0 . 105