1.\" $OpenBSD: pthread_rwlock_wrlock.3,v 1.4 2000/04/12 21:48:02 aaron 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 August 4, 1998
29.Dt PTHREAD_RWLOCK_WRLOCK 3
30.Os
31.Sh NAME
32.Nm pthread_rwlock_wrlock ,
33.Nm pthread_rwlock_trywrlock
34.Nd acquire a read/write lock for writing
35.Sh SYNOPSIS
36.Fd #include <pthread.h>
37.Ft int
38.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock"
39.Ft int
40.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock"
41.Sh DESCRIPTION
42The
43.Fn pthread_rwlock_wrlock
44function blocks until a write lock can be acquired against
45.Fa lock .
46The
47.Fn pthread_rwlock_trywrlock
48function performs the same action, but does not block if the lock
49cannot be immediately obtained.
50.Pp
51The results are undefined if the calling thread already holds the
52lock at the time the call is made.
53.Sh IMPLEMENTATION NOTES
54To prevent writer starvation, writers are favored over readers.
55.Sh RETURN VALUES
56If successful, the
57.Fn pthread_rwlock_wrlock
58and
59.Fn pthread_rwlock_trywrlock
60functions will return zero.  Otherwise an error number will be returned
61to indicate the error.
62.Sh SEE ALSO
63.Xr pthread_rwlock_trywrlock 3 ,
64.Xr pthread_rwlock_unlock 3 ,
65.Xr pthread_rwlock_wrlock 3
66.Sh STANDARDS
67The
68.Fn pthread_rwlock_wrlock
69and
70.Fn pthread_rwlock_trywrlock
71functions are expected to conform to
72.St -susv2 .
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_wrlock
84and
85.Fn pthread_rwlock_trywrlock
86functions may fail if:
87.Bl -tag -width Er
88.It Bq Er EDEADLK
89The calling thread already owns the read/write lock (for reading
90or writing).
91.It Bq Er EINVAL
92The value specified by
93.Fa lock
94is invalid.
95.It Bq Er ENOMEM
96Insufficient memory exists to initialize the lock (applies to
97statically initialized locks only).
98.El
99.Sh HISTORY
100The
101.Fn pthread_rwlock_wrlock
102function first appeared in
103.Fx 3.0
104and
105.Ox 2.5 .
106