1 .\"
   2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
   3 .\" permission to reproduce portions of its copyrighted documentation.
   4 .\" Original documentation from The Open Group can be obtained online at
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\"
   7 .\" The Institute of Electrical and Electronics Engineers and The Open
   8 .\" Group, have given us permission to reprint portions of their
   9 .\" documentation.
  10 .\"
  11 .\" In the following statement, the phrase ``this text'' refers to portions
  12 .\" of the system documentation.
  13 .\"
  14 .\" Portions of this text are reprinted and reproduced in electronic form
  15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
  16 .\" Standard for Information Technology -- Portable Operating System
  17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
  18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
  19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
  20 .\" between these versions and the original IEEE and The Open Group
  21 .\" Standard, the original IEEE and The Open Group Standard is the referee
  22 .\" document.  The original Standard can be obtained online at
  23 .\" http://www.opengroup.org/unix/online.html.
  24 .\"
  25 .\" This notice shall appear on any product containing this material.
  26 .\"
  27 .\" The contents of this file are subject to the terms of the
  28 .\" Common Development and Distribution License (the "License").
  29 .\" You may not use this file except in compliance with the License.
  30 .\"
  31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  32 .\" or http://www.opensolaris.org/os/licensing.
  33 .\" See the License for the specific language governing permissions
  34 .\" and limitations under the License.
  35 .\"
  36 .\" When distributing Covered Code, include this CDDL HEADER in each
  37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  38 .\" If applicable, add the following below this CDDL HEADER, with the
  39 .\" fields enclosed by brackets "[]" replaced with your own identifying
  40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  41 .\"
  42 .\"
  43 .\" Copyright 1991, 1992, 1994, The X/Open Company Ltd.
  44 .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
  45 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
  46 .\"
  47 .TH PTHREAD_RWLOCK_RDLOCK 3C "Mar 23, 2005"
  48 .SH NAME
  49 pthread_rwlock_rdlock, pthread_rwlock_tryrdlock \- lock or attempt to lock
  50 read-write lock object for reading
  51 .SH SYNOPSIS
  52 .LP
  53 .nf
  54 cc -mt [ \fIflag\fR... ] \fIfile\fR... -lpthread [ \fIlibrary\fR... ]
  55 #include <pthread.h>
  56 
  57 \fBint\fR \fBpthread_rwlock_rdlock\fR(\fBpthread_rwlock_t\fR \fI*rwlock\fR);
  58 .fi
  59 
  60 .LP
  61 .nf
  62 \fBint\fR \fBpthread_rwlock_tryrdlock\fR(\fBpthread_rwlock_t\fR \fI*rwlock\fR);
  63 .fi
  64 
  65 .SH DESCRIPTION
  66 .sp
  67 .LP
  68 The \fBpthread_rwlock_rdlock()\fR function applies a read lock to the
  69 read-write lock referenced by \fIrwlock\fR.  The calling thread acquires the
  70 read lock if a writer does not hold the lock and there are no writers blocked
  71 on the lock.
  72 .sp
  73 .LP
  74 The calling thread does not acquire the lock if a writer holds the lock or if
  75 writers of higher or equal priority are blocked on the lock; otherwise, the
  76 calling thread acquires the lock. If the read lock is not acquired, the calling
  77 thread blocks until it can acquire the lock.
  78 .sp
  79 .LP
  80 A thread can hold multiple concurrent read locks on \fIrwlock\fR (that is,
  81 successfully call the \fBpthread_rwlock_rdlock()\fR function \fIn\fR times). If
  82 so, the thread must perform matching unlocks (that is, it must call the
  83 \fBpthread_rwlock_unlock()\fR function \fIn\fR times).
  84 .sp
  85 .LP
  86 The maximum number of concurrent read locks that a thread can hold on one
  87 read-write lock is currently set at 100,000, though this number could change in
  88 a future release. There is no imposed limit on the number of different threads
  89 that can apply a read lock to one read-write lock.
  90 .sp
  91 .LP
  92 The \fBpthread_rwlock_tryrdlock()\fR function applies a read lock like the
  93 \fBpthread_rwlock_rdlock()\fR function, with the exception that the function
  94 fails if the equivalent \fBpthread_rwlock_rdlock()\fR call would have blocked
  95 the calling thread.  In no case will the \fBpthread_rwlock_tryrdlock()\fR
  96 function ever bloc. It always either acquires the lock or fails and returns
  97 immediately.
  98 .sp
  99 .LP
 100 Results are undefined if any of these functions are called with an
 101 uninitialized read-write lock.
 102 .sp
 103 .LP
 104 If a signal is delivered to a thread waiting for a read-write lock for reading,
 105 upon return from the signal handler the thread resumes waiting for the
 106 read-write lock for reading as if it was not interrupted.
 107 .SH RETURN VALUES
 108 .sp
 109 .LP
 110 If successful, the \fBpthread_rwlock_rdlock()\fR function returns \fB0\fR.
 111 Otherwise, an error number is returned to indicate the error.
 112 .sp
 113 .LP
 114 The \fBpthread_rwlock_tryrdlock()\fR function returns \fB0\fR if the lock for
 115 reading on the read-write lock object referenced by \fIrwlock\fR is acquired.
 116 Otherwise an error number  is returned to indicate the error.
 117 .SH ERRORS
 118 .sp
 119 .LP
 120 The \fBpthread_rwlock_rdlock()\fR and \fBpthread_rwlock_tryrdlock()\fR
 121 functions will fail if:
 122 .sp
 123 .ne 2
 124 .na
 125 \fB\fBEAGAIN\fR\fR
 126 .ad
 127 .RS 10n
 128 The read lock could not be acquired because the maximum number of read locks by
 129 the current thread for \fIrwlock\fR has been exceeded.
 130 .RE
 131 
 132 .sp
 133 .LP
 134 The \fBpthread_rwlock_rdlock()\fR function will fail if:
 135 .sp
 136 .ne 2
 137 .na
 138 \fB\fBEDEADLK\fR\fR
 139 .ad
 140 .RS 11n
 141 The current thread already owns the read-write lock for writing.
 142 .RE
 143 
 144 .sp
 145 .LP
 146 The \fBpthread_rwlock_tryrdlock()\fR function will fail if:
 147 .sp
 148 .ne 2
 149 .na
 150 \fB\fBEBUSY\fR\fR
 151 .ad
 152 .RS 9n
 153 The read-write lock could not be acquired for reading because a writer holds
 154 the lock or a writer with the appropriate priority was blocked on it.
 155 .RE
 156 
 157 .SH ATTRIBUTES
 158 .sp
 159 .LP
 160 See  \fBattributes\fR(5) for descriptions of the following attributes:
 161 .sp
 162 
 163 .sp
 164 .TS
 165 box;
 166 c | c
 167 l | l .
 168 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 169 _
 170 Interface Stability     Standard
 171 _
 172 MT-Level        MT-Safe
 173 .TE
 174 
 175 .SH SEE ALSO
 176 .sp
 177 .LP
 178 \fBpthread_rwlock_init\fR(3C), \fBpthread_rwlock_wrlock\fR(3C),
 179 \fBpthread_rwlockattr_init\fR(3C), \fBpthread_rwlock_unlock\fR(3C),
 180 \fBattributes\fR(5), \fBstandards\fR(5)