1PTHREAD_RWLOCK_RDLOCK(P) POSIX Programmer's Manual PTHREAD_RWLOCK_RDLOCK(P)
2
3
4
6 pthread_rwlock_rdlock, pthread_rwlock_tryrdlock - lock a read-write
7 lock object for reading
8
10 #include <pthread.h>
11
12 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
13 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
14
15
17 The pthread_rwlock_rdlock() function shall apply a read lock to the
18 read-write lock referenced by rwlock. The calling thread acquires the
19 read lock if a writer does not hold the lock and there are no writers
20 blocked on the lock.
21
22 If the Thread Execution Scheduling option is supported, and the threads
23 involved in the lock are executing with the scheduling policies
24 SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock
25 if a writer holds the lock or if writers of higher or equal priority
26 are blocked on the lock; otherwise, the calling thread shall acquire
27 the lock.
28
29 If the Threads Execution Scheduling option is supported, and the
30 threads involved in the lock are executing with the SCHED_SPORADIC
31 scheduling policy, the calling thread shall not acquire the lock if a
32 writer holds the lock or if writers of higher or equal priority are
33 blocked on the lock; otherwise, the calling thread shall acquire the
34 lock.
35
36 If the Thread Execution Scheduling option is not supported, it is
37 implementation-defined whether the calling thread acquires the lock
38 when a writer does not hold the lock and there are writers blocked on
39 the lock. If a writer holds the lock, the calling thread shall not
40 acquire the read lock. If the read lock is not acquired, the calling
41 thread shall block until it can acquire the lock. The calling thread
42 may deadlock if at the time the call is made it holds a write lock.
43
44 A thread may hold multiple concurrent read locks on rwlock (that is,
45 successfully call the pthread_rwlock_rdlock() function n times). If so,
46 the application shall ensure that the thread performs matching unlocks
47 (that is, it calls the pthread_rwlock_unlock() function n times).
48
49 The maximum number of simultaneous read locks that an implementation
50 guarantees can be applied to a read-write lock shall be implementation-
51 defined. The pthread_rwlock_rdlock() function may fail if this maximum
52 would be exceeded.
53
54 The pthread_rwlock_tryrdlock() function shall apply a read lock as in
55 the pthread_rwlock_rdlock() function, with the exception that the func‐
56 tion shall fail if the equivalent pthread_rwlock_rdlock() call would
57 have blocked the calling thread. In no case shall the
58 pthread_rwlock_tryrdlock() function ever block; it always either
59 acquires the lock or fails and returns immediately.
60
61 Results are undefined if any of these functions are called with an
62 uninitialized read-write lock.
63
64 If a signal is delivered to a thread waiting for a read-write lock for
65 reading, upon return from the signal handler the thread resumes waiting
66 for the read-write lock for reading as if it was not interrupted.
67
69 If successful, the pthread_rwlock_rdlock() function shall return zero;
70 otherwise, an error number shall be returned to indicate the error.
71
72 The pthread_rwlock_tryrdlock() function shall return zero if the lock
73 for reading on the read-write lock object referenced by rwlock is
74 acquired. Otherwise, an error number shall be returned to indicate the
75 error.
76
78 The pthread_rwlock_tryrdlock() function shall fail if:
79
80 EBUSY The read-write lock could not be acquired for reading because a
81 writer holds the lock or a writer with the appropriate priority
82 was blocked on it.
83
84
85 The pthread_rwlock_rdlock() and pthread_rwlock_tryrdlock() functions
86 may fail if:
87
88 EINVAL The value specified by rwlock does not refer to an initialized
89 read-write lock object.
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
95 The pthread_rwlock_rdlock() function may fail if:
96
97 EDEADLK
98 The current thread already owns the read-write lock for writing.
99
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
111 IEEE Std 1003.1-2001, Section 3.285, Priority Inversion.
112
114 None.
115
117 None.
118
120 pthread_rwlock_destroy() , pthread_rwlock_timedrdlock() ,
121 pthread_rwlock_timedwrlock() , pthread_rwlock_trywrlock() ,
122 pthread_rwlock_unlock() , pthread_rwlock_wrlock() , the Base Defini‐
123 tions volume of IEEE Std 1003.1-2001, <pthread.h>
124
126 Portions of this text are reprinted and reproduced in electronic form
127 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
128 -- Portable Operating System Interface (POSIX), The Open Group Base
129 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
130 Electrical and Electronics Engineers, Inc and The Open Group. In the
131 event of any discrepancy between this version and the original IEEE and
132 The Open Group Standard, the original IEEE and The Open Group Standard
133 is the referee document. The original Standard can be obtained online
134 at http://www.opengroup.org/unix/online.html .
135
136
137
138IEEE/The Open Group 2003 PTHREAD_RWLOCK_RDLOCK(P)