Print this page
12309 errors in section 9e of the manual

Split Close
Expand all
Collapse all
          --- old/usr/src/man/man3c/cond_init.3c
          +++ new/usr/src/man/man3c/cond_init.3c
↓ open down ↓ 36 lines elided ↑ open up ↑
  37   37  .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  38   38  .\" If applicable, add the following below this CDDL HEADER, with the
  39   39  .\" fields enclosed by brackets "[]" replaced with your own identifying
  40   40  .\" information: Portions Copyright [yyyy] [name of copyright owner]
  41   41  .\"
  42   42  .\"
  43   43  .\" Portions Copyright (c) 1995 IEEE.  All Rights Reserved.
  44   44  .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
  45   45  .\" Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
  46   46  .\"
  47      -.TH COND_INIT 3C "Jun 5, 2007"
       47 +.TH COND_INIT 3C "February 15, 2020"
  48   48  .SH NAME
  49   49  cond_init, cond_wait, cond_timedwait, cond_reltimedwait, cond_signal,
  50   50  cond_broadcast, cond_destroy \- condition variables
  51   51  .SH SYNOPSIS
  52      -.LP
  53   52  .nf
  54   53  cc -mt [ \fIflag\fR... ] \fIfile\fR... [ \fIlibrary\fR... ]
  55   54  #include <thread.h>
  56   55  #include <synch.h>
  57   56  
  58   57  \fBint\fR \fBcond_init\fR(\fBcond_t *\fR\fIcvp\fR, \fBint\fR \fItype\fR, \fBvoid *\fR\fIarg\fR);
  59   58  .fi
  60   59  
  61   60  .LP
  62   61  .nf
↓ open down ↓ 22 lines elided ↑ open up ↑
  85   84  \fBint\fR \fBcond_broadcast\fR(\fBcond_t *\fR\fIcvp\fR);
  86   85  .fi
  87   86  
  88   87  .LP
  89   88  .nf
  90   89  \fBint\fR \fBcond_destroy\fR(\fBcond_t *\fR\fIcvp\fR);
  91   90  .fi
  92   91  
  93   92  .SH DESCRIPTION
  94   93  .SS "Initialize"
  95      -.sp
  96      -.LP
  97   94  Condition variables and mutexes should be global. Condition variables that are
  98   95  allocated in writable memory can synchronize threads among processes if they
  99   96  are shared by the cooperating processes (see \fBmmap\fR(2)) and are initialized
 100   97  for this purpose.
 101   98  .sp
 102   99  .LP
 103  100  The scope of a condition variable is either intra-process or inter-process.
 104  101  This is dependent upon whether the argument is passed implicitly or explicitly
 105  102  to the initialization of that condition variable. A condition variable does not
 106  103  need to be explicitly initialized. A condition variable is initialized with all
↓ open down ↓ 5 lines elided ↑ open up ↑
 112  109  A condition variable must not be simultaneously initialized by multiple threads
 113  110  or re-initialized while in use by other threads.
 114  111  .sp
 115  112  .LP
 116  113  Attributes of condition variables can be set to the default or customized at
 117  114  initialization.
 118  115  .sp
 119  116  .LP
 120  117  The \fBcond_init()\fR function initializes the condition variable pointed to by
 121  118  \fIcvp\fR. A condition variable can have several different types of behavior,
 122      -specified by \fItype\fR. No current type uses  \fIarg\fR although a future type
      119 +specified by \fItype\fR. No current type uses \fIarg\fR although a future type
 123  120  may specify additional behavior parameters with \fIarg\fR. The \fItype\fR
 124  121  argument c take one of the following values:
 125  122  .sp
 126  123  .ne 2
 127  124  .na
 128  125  \fB\fBUSYNC_THREAD\fR\fR
 129  126  .ad
 130  127  .RS 17n
 131      -The condition variable can synchronize  threads only in this process. This is
      128 +The condition variable can synchronize threads only in this process. This is
 132  129  the default.
 133  130  .RE
 134  131  
 135  132  .sp
 136  133  .ne 2
 137  134  .na
 138  135  \fB\fBUSYNC_PROCESS\fR\fR
 139  136  .ad
 140  137  .RS 17n
 141  138  The condition variable can synchronize threads in this process and other
↓ open down ↓ 50 lines elided ↑ open up ↑
 192  189  Customized condition variable initialization (inter-process):
 193  190  .sp
 194  191  .in +2
 195  192  .nf
 196  193  cond_init(&cvp, USYNC_PROCESS, NULL); /* initialize cv with
 197  194                                          inter-process scope */
 198  195  .fi
 199  196  .in -2
 200  197  
 201  198  .SS "Condition Wait"
 202      -.sp
 203      -.LP
 204  199  The condition wait interface allows a thread to wait for a condition and
 205  200  atomically release the associated mutex that it needs to hold to check the
 206  201  condition. The thread waits for another thread to make the condition true and
 207  202  that thread's resulting call to signal and wakeup the waiting thread.
 208  203  .sp
 209  204  .LP
 210  205  The \fBcond_wait()\fR function atomically releases the mutex pointed to by
 211  206  \fImp\fR and causes the calling thread to block on the condition variable
 212  207  pointed to by \fIcvp\fR. The blocked thread may be awakened by
 213  208  \fBcond_signal()\fR, \fBcond_broadcast()\fR, or when interrupted by delivery of
 214      -a  \fBUNIX\fR signal or a \fBfork()\fR.
      209 +a \fBUNIX\fR signal or a \fBfork()\fR.
 215  210  .sp
 216  211  .LP
 217  212  The \fBcond_wait()\fR, \fBcond_timedwait()\fR, and \fBcond_reltimedwait()\fR
 218  213  functions always return with the mutex locked and owned by the calling thread
 219  214  even when returning an error, except when the mutex has the \fBLOCK_ROBUST\fR
 220  215  attribute and has been left irrecoverable by the mutex's last owner. The
 221  216  \fBcond_wait()\fR, \fBcond_timedwait()\fR, and \fBcond_reltimedwait()\fR
 222  217  functions return the appropriate error value if they fail to internally
 223  218  reacquire the mutex.
 224  219  .SS "Condition Signaling"
 225      -.sp
 226      -.LP
 227  220  A condition signal allows a thread to unblock a single thread waiting on the
 228  221  condition variable, whereas a condition broadcast allows a thread to unblock
 229  222  all threads waiting on the condition variable.
 230  223  .sp
 231  224  .LP
 232  225  The \fBcond_signal()\fR function unblocks one thread that is blocked on the
 233  226  condition variable pointed to by \fIcvp\fR.
 234  227  .sp
 235  228  .LP
 236  229  The \fBcond_broadcast()\fR function unblocks all threads that are blocked on
↓ open down ↓ 4 lines elided ↑ open up ↑
 241  234  and \fBcond_broadcast()\fR have no effect.
 242  235  .sp
 243  236  .LP
 244  237  The \fBcond_signal()\fR or \fBcond_broadcast()\fR functions can be called by a
 245  238  thread whether or not it currently owns the mutex that threads calling
 246  239  \fBcond_wait()\fR, \fBcond_timedwait()\fR, or \fBcond_reltimedwait()\fR have
 247  240  associated with the condition variable during their waits. If, however,
 248  241  predictable scheduling behavior is required, then that mutex should be locked
 249  242  by the thread prior to calling \fBcond_signal()\fR or \fBcond_broadcast()\fR.
 250  243  .SS "Destroy"
 251      -.sp
 252      -.LP
 253  244  The condition destroy functions destroy any state, but not the space,
 254  245  associated with the condition variable.
 255  246  .sp
 256  247  .LP
 257  248  The \fBcond_destroy()\fR function destroys any state associated with the
 258  249  condition variable pointed to by \fIcvp\fR. The space for storing the condition
 259  250  variable is not freed.
 260  251  .SH RETURN VALUES
 261      -.sp
 262      -.LP
 263  252  Upon successful completion, these functions return \fB0\fR. Otherwise, a
 264  253  non-zero value is returned to indicate the error.
 265  254  .SH ERRORS
 266      -.sp
 267      -.LP
 268  255  The \fBcond_timedwait()\fR and \fBcond_reltimedwait()\fR functions will fail
 269  256  if:
 270  257  .sp
 271  258  .ne 2
 272  259  .na
 273  260  \fB\fBETIME\fR\fR
 274  261  .ad
 275  262  .RS 9n
 276  263  The time specified by \fIabstime\fR or \fIreltime\fR has passed.
 277  264  .RE
↓ open down ↓ 28 lines elided ↑ open up ↑
 306  293  The mutex was protecting the state that has now been left irrecoverable. The
 307  294  mutex has not been acquired.
 308  295  .RE
 309  296  
 310  297  .sp
 311  298  .ne 2
 312  299  .na
 313  300  \fB\fBEOWNERDEAD\fR\fR
 314  301  .ad
 315  302  .RS 19n
 316      -The last owner of the mutex died while  holding the mutex, possibly leaving the
      303 +The last owner of the mutex died while holding the mutex, possibly leaving the
 317  304  state it was protecting inconsistent. The mutex is now owned by the caller.
 318  305  .RE
 319  306  
 320  307  .sp
 321  308  .LP
 322  309  These functions may fail if:
 323  310  .sp
 324  311  .ne 2
 325  312  .na
 326  313  \fB\fBEFAULT\fR\fR
↓ open down ↓ 8 lines elided ↑ open up ↑
 335  322  .na
 336  323  \fB\fBEINVAL\fR\fR
 337  324  .ad
 338  325  .RS 10n
 339  326  Invalid argument. For \fBcond_init()\fR, \fItype\fR is not a recognized type.
 340  327  For \fBcond_timedwait()\fR, the number of nanoseconds is greater than or equal
 341  328  to 1,000,000,000.
 342  329  .RE
 343  330  
 344  331  .SH EXAMPLES
 345      -.LP
 346  332  \fBExample 1 \fRUse \fBcond_wait()\fR in a loop to test some condition.
 347  333  .sp
 348  334  .LP
 349      -The \fBcond_wait()\fR functin is normally used in a loop testing some
      335 +The \fBcond_wait()\fR function is normally used in a loop testing some
 350  336  condition, as follows:
 351  337  
 352  338  .sp
 353  339  .in +2
 354  340  .nf
 355  341  (void) mutex_lock(mp);
 356  342  while (cond == FALSE) {
 357  343       (void) cond_wait(cvp, mp);
 358  344  }
 359  345  (void) mutex_unlock(mp);
↓ open down ↓ 46 lines elided ↑ open up ↑
 406  392       if (err == ETIME) {
 407  393            /* timeout, do something */
 408  394            break;
 409  395       }
 410  396  }
 411  397  (void) mutex_unlock(mp);
 412  398  .fi
 413  399  .in -2
 414  400  
 415  401  .SH ATTRIBUTES
 416      -.sp
 417      -.LP
 418  402  See \fBattributes\fR(5) for descriptions of the following attributes:
 419  403  .sp
 420  404  
 421  405  .sp
 422  406  .TS
 423  407  box;
 424  408  c | c
 425  409  l | l .
 426  410  ATTRIBUTE TYPE  ATTRIBUTE VALUE
 427  411  _
 428  412  MT-Level        MT-Safe
 429  413  .TE
 430  414  
 431  415  .SH SEE ALSO
 432      -.sp
 433      -.LP
 434  416  \fBfork\fR(2), \fBmmap\fR(2), \fBsetitimer\fR(2), \fBshmop\fR(2),
 435  417  \fBmutex_init\fR(3C), \fBsignal\fR(3C), \fBattributes\fR(5),
 436  418  \fBcondition\fR(5), \fBmutex\fR(5), \fBstandards\fR(5)
 437  419  .SH NOTES
 438      -.sp
 439      -.LP
 440  420  If more than one thread is blocked on a condition variable, the order in which
 441  421  threads are unblocked is determined by the scheduling policy. When each thread,
 442  422  unblocked as a result of a \fBcond_signal()\fR or \fBcond_broadcast()\fR,
 443  423  returns from its call to \fBcond_wait()\fR or \fBcond_timedwait()\fR , the
 444  424  thread owns the mutex with which it called \fBcond_wait()\fR,
 445  425  \fBcond_timedwait()\fR, or \fBcond_reltimedwait()\fR. The thread(s) that are
 446  426  unblocked compete for the mutex according to the scheduling policy and as if
 447  427  each had called \fBmutex_lock\fR(3C).
 448  428  .sp
 449  429  .LP
↓ open down ↓ 12 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX