PTHREAD_RWLOCK_RDLOCK(3C) Standard C Library Functions NNAAMMEE pthread_rwlock_rdlock, pthread_rwlock_tryrdlock - lock or attempt to lock read-write lock object for reading SSYYNNOOPPSSIISS cc -mt [ _f_l_a_g... ] _f_i_l_e... -lpthread [ _l_i_b_r_a_r_y... ] #include iinntt pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(pptthhrreeaadd__rrwwlloocckk__tt _*_r_w_l_o_c_k); iinntt pptthhrreeaadd__rrwwlloocckk__ttrryyrrddlloocckk(pptthhrreeaadd__rrwwlloocckk__tt _*_r_w_l_o_c_k); DDEESSCCRRIIPPTTIIOONN The pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) function applies a read lock to the read- write lock referenced by _r_w_l_o_c_k. The calling thread acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock. The calling thread does not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread acquires the lock. If the read lock is not acquired, the calling thread blocks until it can acquire the lock. A thread can hold multiple concurrent read locks on _r_w_l_o_c_k (that is, successfully call the pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) function _n times). If so, the thread must perform matching unlocks (that is, it must call the pptthhrreeaadd__rrwwlloocckk__uunnlloocckk(()) function _n times). The maximum number of concurrent read locks that a thread can hold on one read-write lock is currently set at 100,000, though this number could change in a future release. There is no imposed limit on the number of different threads that can apply a read lock to one read- write lock. The pptthhrreeaadd__rrwwlloocckk__ttrryyrrddlloocckk(()) function applies a read lock like the pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) function, with the exception that the function fails if the equivalent pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) call would have blocked the calling thread. In no case will the pptthhrreeaadd__rrwwlloocckk__ttrryyrrddlloocckk(()) function ever block. It always either acquires the lock or fails and returns immediately. Results are undefined if any of these functions are called with an uninitialized read-write lock. If a signal is delivered to a thread waiting for a read-write lock for reading, upon return from the signal handler the thread resumes waiting for the read-write lock for reading as if it was not interrupted. RREETTUURRNN VVAALLUUEESS If successful, the pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) function returns 00. Otherwise, an error number is returned to indicate the error. The pptthhrreeaadd__rrwwlloocckk__ttrryyrrddlloocckk(()) function returns 00 if the lock for reading on the read-write lock object referenced by _r_w_l_o_c_k is acquired. Otherwise an error number is returned to indicate the error. EERRRROORRSS The pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) and pptthhrreeaadd__rrwwlloocckk__ttrryyrrddlloocckk(()) functions will fail if: EEAAGGAAIINN The read lock could not be acquired because the maximum number of read locks by the current thread for _r_w_l_o_c_k has been exceeded. The pptthhrreeaadd__rrwwlloocckk__rrddlloocckk(()) function will fail if: EEDDEEAADDLLKK The current thread already owns the read-write lock for writing. The pptthhrreeaadd__rrwwlloocckk__ttrryyrrddlloocckk(()) function will fail if: EEBBUUSSYY The read-write lock could not be acquired for reading because a writer holds the lock or a writer with the appropriate priority was blocked on it. AATTTTRRIIBBUUTTEESS See aattttrriibbuutteess(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Interface Stability | Standard | +--------------------+-----------------+ |MT-Level | MT-Safe | +--------------------+-----------------+ SSEEEE AALLSSOO pptthhrreeaadd__rrwwlloocckk__iinniitt(3C), pptthhrreeaadd__rrwwlloocckk__wwrrlloocckk(3C), pptthhrreeaadd__rrwwlloocckkaattttrr__iinniitt(3C), pptthhrreeaadd__rrwwlloocckk__uunnlloocckk(3C), aattttrriibbuutteess(5), ssttaannddaarrddss(5) March 23, 2005 PTHREAD_RWLOCK_RDLOCK(3C)