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