xref: /openbsd-src/lib/libpthread/man/pthread_rwlock_wrlock.3 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\" $OpenBSD: pthread_rwlock_wrlock.3,v 1.7 2007/05/31 19:19:37 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 31 2007 $
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.
61Otherwise an error number will be returned to indicate the error.
62.Sh ERRORS
63The
64.Fn pthread_rwlock_trywrlock
65function will fail if:
66.Bl -tag -width Er
67.It Bq Er EBUSY
68The calling thread is not able to acquire the lock without blocking.
69.El
70.Pp
71The
72.Fn pthread_rwlock_wrlock
73and
74.Fn pthread_rwlock_trywrlock
75functions may fail if:
76.Bl -tag -width Er
77.It Bq Er EDEADLK
78The calling thread already owns the read/write lock (for reading
79or writing).
80.It Bq Er EINVAL
81The value specified by
82.Fa lock
83is invalid.
84.It Bq Er ENOMEM
85Insufficient memory exists to initialize the lock (applies to
86statically initialized locks only).
87.El
88.Sh SEE ALSO
89.Xr pthread_rwlock_unlock 3
90.Sh STANDARDS
91The
92.Fn pthread_rwlock_wrlock
93and
94.Fn pthread_rwlock_trywrlock
95functions are expected to conform to
96.St -susv2 .
97.Sh HISTORY
98The
99.Fn pthread_rwlock_wrlock
100function first appeared in
101.Fx 3.0
102and
103.Ox 2.5 .
104