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 .LP
  67 The \fBpthread_rwlock_rdlock()\fR function applies a read lock to the
  68 read-write lock referenced by \fIrwlock\fR.  The calling thread acquires the
  69 read lock if a writer does not hold the lock and there are no writers blocked
  70 on the lock.
  71 .sp
  72 .LP
  73 The calling thread does not acquire the lock if a writer holds the lock or if
  74 writers of higher or equal priority are blocked on the lock; otherwise, the
  75 calling thread acquires the lock. If the read lock is not acquired, the calling
  76 thread blocks until it can acquire the lock.
  77 .sp
  78 .LP
  79 A thread can hold multiple concurrent read locks on \fIrwlock\fR (that is,
  80 successfully call the \fBpthread_rwlock_rdlock()\fR function \fIn\fR times). If
  81 so, the thread must perform matching unlocks (that is, it must call the
  82 \fBpthread_rwlock_unlock()\fR function \fIn\fR times).
  83 .sp
  84 .LP
  85 The maximum number of concurrent read locks that a thread can hold on one
  86 read-write lock is currently set at 100,000, though this number could change in
  87 a future release. There is no imposed limit on the number of different threads
  88 that can apply a read lock to one read-write lock.
  89 .sp
  90 .LP
  91 The \fBpthread_rwlock_tryrdlock()\fR function applies a read lock like the
  92 \fBpthread_rwlock_rdlock()\fR function, with the exception that the function
  93 fails if the equivalent \fBpthread_rwlock_rdlock()\fR call would have blocked
  94 the calling thread.  In no case will the \fBpthread_rwlock_tryrdlock()\fR
  95 function ever block. It always either acquires the lock or fails and returns
  96 immediately.
  97 .sp
  98 .LP
  99 Results are undefined if any of these functions are called with an
 100 uninitialized read-write lock.
 101 .sp
 102 .LP
 103 If a signal is delivered to a thread waiting for a read-write lock for reading,
 104 upon return from the signal handler the thread resumes waiting for the
 105 read-write lock for reading as if it was not interrupted.
 106 .SH RETURN VALUES
 107 .LP
 108 If successful, the \fBpthread_rwlock_rdlock()\fR function returns \fB0\fR.
 109 Otherwise, an error number is returned to indicate the error.
 110 .sp
 111 .LP
 112 The \fBpthread_rwlock_tryrdlock()\fR function returns \fB0\fR if the lock for
 113 reading on the read-write lock object referenced by \fIrwlock\fR is acquired.
 114 Otherwise an error number  is returned to indicate the error.
 115 .SH ERRORS
 116 .LP
 117 The \fBpthread_rwlock_rdlock()\fR and \fBpthread_rwlock_tryrdlock()\fR
 118 functions will fail if:
 119 .sp
 120 .ne 2
 121 .na
 122 \fB\fBEAGAIN\fR\fR
 123 .ad
 124 .RS 10n
 125 The read lock could not be acquired because the maximum number of read locks by
 126 the current thread for \fIrwlock\fR has been exceeded.
 127 .RE
 128 
 129 .sp
 130 .LP
 131 The \fBpthread_rwlock_rdlock()\fR function will fail if:
 132 .sp
 133 .ne 2
 134 .na
 135 \fB\fBEDEADLK\fR\fR
 136 .ad
 137 .RS 11n
 138 The current thread already owns the read-write lock for writing.
 139 .RE
 140 
 141 .sp
 142 .LP
 143 The \fBpthread_rwlock_tryrdlock()\fR function will fail if:
 144 .sp
 145 .ne 2
 146 .na
 147 \fB\fBEBUSY\fR\fR
 148 .ad
 149 .RS 9n
 150 The read-write lock could not be acquired for reading because a writer holds
 151 the lock or a writer with the appropriate priority was blocked on it.
 152 .RE
 153 
 154 .SH ATTRIBUTES
 155 .LP
 156 See  \fBattributes\fR(5) for descriptions of the following attributes:
 157 .sp
 158 
 159 .sp
 160 .TS
 161 box;
 162 c | c
 163 l | l .
 164 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 165 _
 166 Interface Stability     Standard
 167 _
 168 MT-Level        MT-Safe
 169 .TE
 170 
 171 .SH SEE ALSO
 172 .LP
 173 \fBpthread_rwlock_init\fR(3C), \fBpthread_rwlock_wrlock\fR(3C),
 174 \fBpthread_rwlockattr_init\fR(3C), \fBpthread_rwlock_unlock\fR(3C),
 175 \fBattributes\fR(5), \fBstandards\fR(5)