Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > ed376d6842ea322c25405e7c23b3bc12 > files > 313

libcommoncpp-devel-1.8.0-5.1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>GNU CommonC++: ost::Semaphore Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="classes.html"><span>Class&nbsp;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceost.html">ost</a>::<a class="el" href="classost_1_1_semaphore.html">Semaphore</a>
  </div>
</div>
<div class="contents">
<h1>ost::Semaphore Class Reference</h1><!-- doxytag: class="ost::Semaphore" -->
<p>A semaphore is generally used as a synchronization object between multiple threads or to protect a limited and finite resource such as a memory or thread pool.  
<a href="#_details">More...</a></p>

<p><code>#include &lt;<a class="el" href="thread_8h_source.html">thread.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for ost::Semaphore:</div>
<div class="dynsection">
 <div class="center">
  <img src="classost_1_1_semaphore.png" usemap="#ost::Semaphore_map" alt=""/>
  <map id="ost::Semaphore_map" name="ost::Semaphore_map">
<area href="classost_1_1_thread_queue.html" alt="ost::ThreadQueue" shape="rect" coords="0,56,112,80"/>
</map>
 </div>
</div>

<p><a href="classost_1_1_semaphore-members.html">List of all members.</a></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classost_1_1_semaphore.html#a0a6f933da386bbe01b2b0b6b266bcc85">Semaphore</a> (unsigned resource=0)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The initial value of the semaphore can be specified.  <a href="#a0a6f933da386bbe01b2b0b6b266bcc85"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classost_1_1_semaphore.html#a138de594478446aa07f3bad15dce3846">~Semaphore</a> ()</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destroying a semaphore also removes any system resources associated with it.  <a href="#a138de594478446aa07f3bad15dce3846"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classost_1_1_semaphore.html#a1f2526be16a463d2392a74f668a91d80">wait</a> (<a class="el" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a> timeout=0)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Wait is used to keep a thread held until the semaphore counter is greater than 0.  <a href="#a1f2526be16a463d2392a74f668a91d80"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classost_1_1_semaphore.html#a7535c9c3f3c60596b21b5275342cbe1e">post</a> (void)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Posting to a semaphore increments its current value and releases the first thread waiting for the semaphore if it is currently at 0.  <a href="#a7535c9c3f3c60596b21b5275342cbe1e"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classost_1_1_semaphore.html#a23c458d249a3f68b83deaa5c7986dfca">force_unlock_after_cancellation</a> ()</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Call it after a deferred cancellation to avoid deadlocks.  <a href="#a23c458d249a3f68b83deaa5c7986dfca"></a><br/></td></tr>
</table>
<hr/><a name="_details"></a><h2>Detailed Description</h2>
<p>A semaphore is generally used as a synchronization object between multiple threads or to protect a limited and finite resource such as a memory or thread pool. </p>
<p>The semaphore has a counter which only permits access by one or more threads when the value of the semaphore is non-zero. Each access reduces the current value of the semaphore by 1. One or more threads can wait on a semaphore until it is no longer 0, and hence the semaphore can be used as a simple thread synchronization object to enable one thread to pause others until the thread is ready or has provided data for them. Semaphores are typically used as a counter for protecting or limiting concurrent access to a given resource, such as to permitting at most "x" number of threads to use resource "y", for example.</p>
<dl class="author"><dt><b>Author:</b></dt><dd>David Sugar &lt;<a href="mailto:dyfet@ostel.com">dyfet@ostel.com</a>&gt; <a class="el" href="classost_1_1_semaphore.html" title="A semaphore is generally used as a synchronization object between multiple threads...">Semaphore</a> counter for thread synchronization. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd>
<p><a class="el" href="tcpservice_8cpp-example.html#_a15">tcpservice.cpp</a>.</p>
</dd>
</dl><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a0a6f933da386bbe01b2b0b6b266bcc85"></a><!-- doxytag: member="ost::Semaphore::Semaphore" ref="a0a6f933da386bbe01b2b0b6b266bcc85" args="(unsigned resource=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">ost::Semaphore::Semaphore </td>
          <td>(</td>
          <td class="paramtype">unsigned&nbsp;</td>
          <td class="paramname"> <em>resource</em> = <code>0</code></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>The initial value of the semaphore can be specified. </p>
<p>An initial value is often used When used to lock a finite resource or to specify the maximum number of thread instances that can access a specified resource.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>resource</em>&nbsp;</td><td>specify initial resource count or 0 default. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="a138de594478446aa07f3bad15dce3846"></a><!-- doxytag: member="ost::Semaphore::~Semaphore" ref="a138de594478446aa07f3bad15dce3846" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual ost::Semaphore::~Semaphore </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Destroying a semaphore also removes any system resources associated with it. </p>
<p>If a semaphore has threads currently waiting on it, those threads will all continue when a semaphore is destroyed. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a23c458d249a3f68b83deaa5c7986dfca"></a><!-- doxytag: member="ost::Semaphore::force_unlock_after_cancellation" ref="a23c458d249a3f68b83deaa5c7986dfca" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void ost::Semaphore::force_unlock_after_cancellation </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Call it after a deferred cancellation to avoid deadlocks. </p>
<p>From PTHREAD_COND_TIMEDWAIT(3P): A condition wait (whether timed or not) is a cancellation point. When the cancelability enable state of a thread is set to PTHREAD_CANCEL_DEFERRED, a side effect of acting upon a cancellation request while in a condition wait is that the mutex is (in effect) re-acquired before calling the first cancellation cleanup handler. </p>

</div>
</div>
<a class="anchor" id="a7535c9c3f3c60596b21b5275342cbe1e"></a><!-- doxytag: member="ost::Semaphore::post" ref="a7535c9c3f3c60596b21b5275342cbe1e" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void ost::Semaphore::post </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Posting to a semaphore increments its current value and releases the first thread waiting for the semaphore if it is currently at 0. </p>
<p>Interestingly, there is no support to increment a semaphore by any value greater than 1 to release multiple waiting threads in either pthread or the win32 API. Hence, if one wants to release a semaphore to enable multiple threads to execute, one must perform multiple post operations.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classost_1_1_semaphore.html#a1f2526be16a463d2392a74f668a91d80" title="Wait is used to keep a thread held until the semaphore counter is greater than 0...">wait</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a1f2526be16a463d2392a74f668a91d80"></a><!-- doxytag: member="ost::Semaphore::wait" ref="a1f2526be16a463d2392a74f668a91d80" args="(timeout_t timeout=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool ost::Semaphore::wait </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="thread_8h.html#af412159e5cef839836a5e7b19ee75d1c">timeout_t</a>&nbsp;</td>
          <td class="paramname"> <em>timeout</em> = <code>0</code></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Wait is used to keep a thread held until the semaphore counter is greater than 0. </p>
<p>If the current thread is held, then another thread must increment the semaphore. Once the thread is accepted, the semaphore is automatically decremented, and the thread continues execution.</p>
<p>The pthread semaphore object does not support a timed "wait", and hence to maintain consistancy, neither the posix nor win32 source trees support "timed" semaphore objects.</p>
<dl class="return"><dt><b>Returns:</b></dt><dd>false if timed out </dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>timeout</em>&nbsp;</td><td>period in milliseconds to wait </td></tr>
  </table>
  </dd>
</dl>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classost_1_1_semaphore.html#a7535c9c3f3c60596b21b5275342cbe1e" title="Posting to a semaphore increments its current value and releases the first thread...">post</a> </dd></dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="thread_8h_source.html">thread.h</a></li>
</ul>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Fri Nov 12 09:55:47 2010 for GNU CommonC++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>