1PTHREAD_RWLOCK_RDLOCK(3P)  POSIX Programmer's Manual PTHREAD_RWLOCK_RDLOCK(3P)
2
3
4

PROLOG

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

NAME

12       pthread_rwlock_rdlock, pthread_rwlock_tryrdlock  -  lock  a  read-write
13       lock object for reading
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
19       int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
20
21

DESCRIPTION

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  Threads  Execution  Scheduling  option  is  supported, and the
36       threads involved in the lock  are  executing  with  the  SCHED_SPORADIC
37       scheduling  policy,  the calling thread shall not acquire the lock if a
38       writer holds the lock or if writers of higher  or  equal  priority  are
39       blocked  on  the  lock; otherwise, the calling thread shall acquire the
40       lock.
41
42       If the Thread Execution Scheduling  option  is  not  supported,  it  is
43       implementation-defined  whether  the  calling  thread acquires the lock
44       when a writer does not hold the lock and there are writers  blocked  on
45       the  lock.  If  a  writer  holds the lock, the calling thread shall not
46       acquire the read lock. If the read lock is not  acquired,  the  calling
47       thread  shall  block until it can acquire the lock.  The calling thread
48       may deadlock if at the time the call is made it holds a write lock.
49
50       A thread may hold multiple concurrent read locks on  rwlock  (that  is,
51       successfully call the pthread_rwlock_rdlock() function n times). If so,
52       the application shall ensure that the thread performs matching  unlocks
53       (that is, it calls the pthread_rwlock_unlock() function n times).
54
55       The  maximum  number  of simultaneous read locks that an implementation
56       guarantees can be applied to a read-write lock shall be implementation-
57       defined.  The pthread_rwlock_rdlock() function may fail if this maximum
58       would be exceeded.
59
60       The pthread_rwlock_tryrdlock() function shall apply a read lock  as  in
61       the pthread_rwlock_rdlock() function, with the exception that the func‐
62       tion shall fail if the equivalent  pthread_rwlock_rdlock()  call  would
63       have   blocked   the   calling   thread.   In   no   case   shall   the
64       pthread_rwlock_tryrdlock()  function  ever  block;  it  always   either
65       acquires the lock or fails and returns immediately.
66
67       Results  are  undefined  if  any  of these functions are called with an
68       uninitialized read-write lock.
69
70       If a signal is delivered to a thread waiting for a read-write lock  for
71       reading, upon return from the signal handler the thread resumes waiting
72       for the read-write lock for reading as if it was not interrupted.
73

RETURN VALUE

75       If successful, the pthread_rwlock_rdlock() function shall return  zero;
76       otherwise, an error number shall be returned to indicate the error.
77
78       The  pthread_rwlock_tryrdlock()  function shall return zero if the lock
79       for reading on the read-write  lock  object  referenced  by  rwlock  is
80       acquired.  Otherwise, an error number shall be returned to indicate the
81       error.
82

ERRORS

84       The pthread_rwlock_tryrdlock() function shall fail if:
85
86       EBUSY  The read-write lock could not be acquired for reading because  a
87              writer  holds the lock or a writer with the appropriate priority
88              was blocked on it.
89
90
91       The pthread_rwlock_rdlock()  and  pthread_rwlock_tryrdlock()  functions
92       may fail if:
93
94       EINVAL The  value  specified by rwlock does not refer to an initialized
95              read-write lock object.
96
97       EAGAIN The read lock could not be acquired because the  maximum  number
98              of read locks for rwlock has been exceeded.
99
100
101       The pthread_rwlock_rdlock() function may fail if:
102
103       EDEADLK
104              The current thread already owns the read-write lock for writing.
105
106
107       These functions shall not return an error code of [EINTR].
108
109       The following sections are informative.
110

EXAMPLES

112       None.
113

APPLICATION USAGE

115       Applications  using  these  functions may be subject to priority inver‐
116       sion,   as   discussed   in   the   Base    Definitions    volume    of
117       IEEE Std 1003.1-2001, Section 3.285, Priority Inversion.
118

RATIONALE

120       None.
121

FUTURE DIRECTIONS

123       None.
124

SEE ALSO

126       pthread_rwlock_destroy(),                 pthread_rwlock_timedrdlock(),
127       pthread_rwlock_timedwrlock(),               pthread_rwlock_trywrlock(),
128       pthread_rwlock_unlock(),  pthread_rwlock_wrlock(), the Base Definitions
129       volume of IEEE Std 1003.1-2001, <pthread.h>
130
132       Portions of this text are reprinted and reproduced in  electronic  form
133       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
134       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
135       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
136       Electrical and Electronics Engineers, Inc and The Open  Group.  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.opengroup.org/unix/online.html .
141
142
143
144IEEE/The Open Group                  2003            PTHREAD_RWLOCK_RDLOCK(3P)
Impressum