1PTHREAD_RWLOCK_RDLOCK(3P) POSIX Programmer's Manual PTHREAD_RWLOCK_RDLOCK(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 pthread_rwlock_rdlock, pthread_rwlock_tryrdlock — lock a read-write
14 lock object for reading
15
17 #include <pthread.h>
18
19 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
20 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
21
23 The pthread_rwlock_rdlock() function shall apply a read lock to the
24 read-write lock referenced by rwlock. The calling thread acquires the
25 read lock if a writer does not hold the lock and there are no writers
26 blocked on the lock.
27
28 If the Thread Execution Scheduling option is supported, and the threads
29 involved in the lock are executing with the scheduling policies
30 SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock
31 if a writer holds the lock or if writers of higher or equal priority
32 are blocked on the lock; otherwise, the calling thread shall acquire
33 the lock.
34
35 If the Thread Execution Scheduling option is supported, and the threads
36 involved in the lock are executing with the SCHED_SPORADIC scheduling
37 policy, the calling thread shall not acquire the lock if a writer holds
38 the lock or if writers of higher or equal priority are blocked on the
39 lock; otherwise, the calling thread shall acquire the lock.
40
41 If the Thread Execution Scheduling option is not supported, it is
42 implementation-defined whether the calling thread acquires the lock
43 when a writer does not hold the lock and there are writers blocked on
44 the lock. If a writer holds the lock, the calling thread shall not
45 acquire the read lock. If the read lock is not acquired, the calling
46 thread shall block until it can acquire the lock. The calling thread
47 may deadlock if at the time the call is made it holds a write lock.
48
49 A thread may hold multiple concurrent read locks on rwlock (that is,
50 successfully call the pthread_rwlock_rdlock() function n times). If so,
51 the application shall ensure that the thread performs matching unlocks
52 (that is, it calls the pthread_rwlock_unlock() function n times).
53
54 The maximum number of simultaneous read locks that an implementation
55 guarantees can be applied to a read-write lock shall be implementation-
56 defined. The pthread_rwlock_rdlock() function may fail if this maximum
57 would be exceeded.
58
59 The pthread_rwlock_tryrdlock() function shall apply a read lock as in
60 the pthread_rwlock_rdlock() function, with the exception that the func‐
61 tion shall fail if the equivalent pthread_rwlock_rdlock() call would
62 have blocked the calling thread. In no case shall the
63 pthread_rwlock_tryrdlock() function ever block; it always either
64 acquires the lock or fails and returns immediately.
65
66 Results are undefined if any of these functions are called with an
67 uninitialized read-write lock.
68
69 If a signal is delivered to a thread waiting for a read-write lock for
70 reading, upon return from the signal handler the thread resumes waiting
71 for the read-write lock for reading as if it was not interrupted.
72
74 If successful, the pthread_rwlock_rdlock() function shall return zero;
75 otherwise, an error number shall be returned to indicate the error.
76
77 The pthread_rwlock_tryrdlock() function shall return zero if the lock
78 for reading on the read-write lock object referenced by rwlock is
79 acquired. Otherwise, an error number shall be returned to indicate the
80 error.
81
83 The pthread_rwlock_tryrdlock() function shall fail if:
84
85 EBUSY The read-write lock could not be acquired for reading because a
86 writer holds the lock or a writer with the appropriate priority
87 was blocked on it.
88
89 The pthread_rwlock_rdlock() and pthread_rwlock_tryrdlock() functions
90 may fail if:
91
92 EAGAIN The read lock could not be acquired because the maximum number
93 of read locks for rwlock has been exceeded.
94
95 The pthread_rwlock_rdlock() function may fail if:
96
97 EDEADLK
98 A deadlock condition was detected or the current thread already
99 owns the read-write lock for writing.
100
101 These functions shall not return an error code of [EINTR].
102
103 The following sections are informative.
104
106 None.
107
109 Applications using these functions may be subject to priority inver‐
110 sion, as discussed in the Base Definitions volume of POSIX.1‐2008, Sec‐
111 tion 3.287, Priority Inversion.
112
114 If an implementation detects that the value specified by the rwlock
115 argument to pthread_rwlock_rdlock() or pthread_rwlock_tryrdlock() does
116 not refer to an initialized read-write lock object, it is recommended
117 that the function should fail and report an [EINVAL] error.
118
120 None.
121
123 pthread_rwlock_destroy(), pthread_rwlock_timedrdlock(),
124 pthread_rwlock_timedwrlock(), pthread_rwlock_trywrlock(),
125 pthread_rwlock_unlock()
126
127 The Base Definitions volume of POSIX.1‐2008, Section 3.287, Priority
128 Inversion, Section 4.11, Memory Synchronization, <pthread.h>
129
131 Portions of this text are reprinted and reproduced in electronic form
132 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
133 -- Portable Operating System Interface (POSIX), The Open Group Base
134 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
135 cal and Electronics Engineers, Inc and The Open Group. (This is
136 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
137 event of any discrepancy between this version and the original IEEE and
138 The Open Group Standard, the original IEEE and The Open Group Standard
139 is the referee document. The original Standard can be obtained online
140 at http://www.unix.org/online.html .
141
142 Any typographical or formatting errors that appear in this page are
143 most likely to have been introduced during the conversion of the source
144 files to man page format. To report such errors, see https://www.ker‐
145 nel.org/doc/man-pages/reporting_bugs.html .
146
147
148
149IEEE/The Open Group 2013 PTHREAD_RWLOCK_RDLOCK(3P)