blob: 09591f6c98eddff85d1d29fd8e9554321eb8acc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<table class="head">
<tr>
<td class="head-ltitle">PTHREAD_RWLOCK_WRLOCK(3)</td>
<td class="head-vol">Library Functions Manual</td>
<td class="head-rtitle">PTHREAD_RWLOCK_WRLOCK(3)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">pthread_rwlock_wrlock</code>,
<code class="Nm">pthread_rwlock_trywrlock</code> —
<span class="Nd">acquire a read/write lock for writing</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
<p class="Pp"><span class="Lb">POSIX Threads Library (libpthread,
-lpthread)</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">pthread.h</a>></code></p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">pthread_rwlock_wrlock</code>(<var class="Fa" style="white-space: nowrap;">pthread_rwlock_t
*lock</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">pthread_rwlock_trywrlock</code>(<var class="Fa" style="white-space: nowrap;">pthread_rwlock_t
*lock</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The
<a class="permalink" href="#pthread_rwlock_wrlock"><code class="Fn" id="pthread_rwlock_wrlock">pthread_rwlock_wrlock</code></a>()
function blocks until a write lock can be acquired against
<var class="Fa">lock</var>. The
<a class="permalink" href="#pthread_rwlock_trywrlock"><code class="Fn" id="pthread_rwlock_trywrlock">pthread_rwlock_trywrlock</code></a>()
function performs the same action, but does not block if the lock cannot be
immediately obtained.</p>
<p class="Pp">The results are undefined if the calling thread already holds the
lock at the time the call is made.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="IMPLEMENTATION_NOTES"><a class="permalink" href="#IMPLEMENTATION_NOTES">IMPLEMENTATION
NOTES</a></h1>
<p class="Pp">To prevent writer starvation, writers are favored over
readers.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN
VALUES</a></h1>
<p class="Pp">If successful, the <code class="Fn">pthread_rwlock_wrlock</code>()
and <code class="Fn">pthread_rwlock_trywrlock</code>() functions will return
zero. Otherwise an error number will be returned to indicate the error.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="ERRORS"><a class="permalink" href="#ERRORS">ERRORS</a></h1>
<p class="Pp">The <code class="Fn">pthread_rwlock_trywrlock</code>() function
will fail if:</p>
<dl class="Bl-tag">
<dt id="EBUSY">[<a class="permalink" href="#EBUSY"><code class="Er">EBUSY</code></a>]</dt>
<dd>The calling thread is not able to acquire the lock without blocking.</dd>
</dl>
<p class="Pp">The <code class="Fn">pthread_rwlock_wrlock</code>() and
<code class="Fn">pthread_rwlock_trywrlock</code>() functions may fail
if:</p>
<dl class="Bl-tag">
<dt id="EDEADLK">[<a class="permalink" href="#EDEADLK"><code class="Er">EDEADLK</code></a>]</dt>
<dd>The calling thread already owns the read/write lock (for reading or
writing).</dd>
<dt id="EINVAL">[<a class="permalink" href="#EINVAL"><code class="Er">EINVAL</code></a>]</dt>
<dd>The value specified by <var class="Fa">lock</var> is invalid.</dd>
<dt id="ENOMEM">[<a class="permalink" href="#ENOMEM"><code class="Er">ENOMEM</code></a>]</dt>
<dd>Insufficient memory exists to initialize the lock (applies to statically
initialized locks only).</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr">pthread_rwlock_init(3)</a>,
<a class="Xr">pthread_rwlock_rdlock(3)</a>,
<a class="Xr">pthread_rwlock_tryrdlock(3)</a>,
<a class="Xr">pthread_rwlock_unlock(3)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="STANDARDS"><a class="permalink" href="#STANDARDS">STANDARDS</a></h1>
<p class="Pp">The <code class="Fn">pthread_rwlock_wrlock</code>() and
<code class="Fn">pthread_rwlock_trywrlock</code>() functions are expected to
conform to <span class="St">Version 2 of the Single UNIX
Specification (“SUSv2”)</span>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Fn">pthread_rwlock_wrlock</code>() function first
appeared in <span class="Ux">FreeBSD 3.0</span>.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">August 4, 1998</td>
<td class="foot-os">FreeBSD 15.0</td>
</tr>
</table>
|