66 lines
4.4 KiB
HTML
66 lines
4.4 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="concept" />
|
||
|
<meta name="DC.Title" content="Condition variables and threads" />
|
||
|
<meta name="abstract" content="Condition variables allow threads to wait for certain events or conditions to occur and they notify other threads that are also waiting for the same events or conditions." />
|
||
|
<meta name="description" content="Condition variables allow threads to wait for certain events or conditions to occur and they notify other threads that are also waiting for the same events or conditions." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzahwsynco.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzahwe17rx.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzahwex5rx.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rzahwvar-varco" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Condition variables and threads</title>
|
||
|
</head>
|
||
|
<body id="rzahwvar-varco"><a name="rzahwvar-varco"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Condition variables and threads</h1>
|
||
|
<div><p>Condition variables allow threads to wait for certain events or
|
||
|
conditions to occur and they notify other threads that are also waiting for
|
||
|
the same events or conditions.</p>
|
||
|
<p>The thread can wait on a condition variable and broadcast a condition such
|
||
|
that one or all of the threads that are waiting on the condition variable
|
||
|
become active. You can consider condition variables to be similar to using
|
||
|
events to synchronize threads on other platforms.</p>
|
||
|
<p>Condition variables do not have ownership associated with them and are
|
||
|
typically stateless. A stateless condition variable means that if a thread
|
||
|
signals a condition variable to wake up a waiting thread when there are currently
|
||
|
no waiting threads, the signal is discarded and no action is
|
||
|
taken. The signal is effectively lost. It is possible for one thread to signal
|
||
|
a condition immediately before a different thread begins waiting for it without
|
||
|
any resulting action. </p>
|
||
|
<p>Locking protocols that use mutual exclusions (mutexes)
|
||
|
are typically used with condition variables. If you use locking protocols,
|
||
|
your application can ensure that a thread does not lose a signal that was
|
||
|
intended to wake it up.</p>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="rzahwe17rx.htm">Example: Use condition variables in Pthread programs</a></strong><br />
|
||
|
This example shows a Pthread program using condition variables to notify threads of a condition. Notice what mutual exclusion (mutex) locking protocol is used.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rzahwex5rx.htm">Example: Use condition variables in Java programs</a></strong><br />
|
||
|
This example shows a Java™ program using condition variables in
|
||
|
the form of the wait and notify methods on a Java™ object. Note the locking protocol used.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahwsynco.htm" title="When you create code that is threadsafe but still benefits from sharing data or resources between threads, the most important aspect of programming becomes the ability to synchronize threads.">Synchronization techniques among threads</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|