Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 68d373e54fb21da3730c08bede406633 > files > 256

libCommonC++1.9_3-devel-1.9.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Mutex class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.10 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>Mutex  Class Reference</h1>The Mutex class is used to protect a section of code so that at any given time only a single thread can perform the protected operation. Mutex lock for protected access. 
<a href="#_details">More...</a>
<p>
<code>#include &lt;<a class="el" href="thread_8h-source.html">thread.h</a>&gt;</code>
<p>
<p>Inheritance diagram for Mutex::
<p><center><img src="class_mutex.gif" usemap="#Mutex_map" border="0"></center>
<map name="Mutex_map">
<area href="class_conditional.html" alt="Conditional" shape="rect" coords="0,56,114,80">
<area href="class_mutex_counter.html" alt="MutexCounter" shape="rect" coords="124,56,238,80">
<area href="class_random_file.html" alt="RandomFile" shape="rect" coords="248,56,362,80">
<area href="class_serial_service.html" alt="SerialService" shape="rect" coords="372,56,486,80">
<area href="class_shared_mem_pager.html" alt="SharedMemPager" shape="rect" coords="496,56,610,80">
<area href="class_socket_service.html" alt="SocketService" shape="rect" coords="620,56,734,80">
<area href="class_mapped_file.html" alt="MappedFile" shape="rect" coords="124,112,238,136">
<area href="class_shared_file.html" alt="SharedFile" shape="rect" coords="248,112,362,136">
<area href="class_thread_file.html" alt="ThreadFile" shape="rect" coords="372,112,486,136">
</map>
<a href="class_mutex-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0>
<tr><td colspan=2><br><h2>Public Methods</h2></td></tr>
<tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#a0">Mutex</a> ()</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>The mutex is always initialized as a recursive entity.</em> <a href="#a0">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>virtual&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#a1">~Mutex</a> ()</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Destroying the mutex removes any system resources associated with it.</em> <a href="#a1">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>void&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#a2">EnterMutex</a> (void)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Entering a Mutex locks the mutex for the current thread.</em> <a href="#a2">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>bool&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#a3">TryEnterMutex</a> (void)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Tries to lock the mutex for the current thread.</em> <a href="#a3">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>void&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#a4">LeaveMutex</a> (void)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Leaving a mutex frees that mutex for use by another thread.</em> <a href="#a4">More...</a><em></em></font><br><br></td></tr>
<tr><td colspan=2><br><h2>Friends</h2></td></tr>
<tr><td nowrap align=right valign=top>class&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#l0">Conditional</a></td></tr>
<tr><td nowrap align=right valign=top>class&nbsp;</td><td valign=bottom><a class="el" href="class_mutex.html#l1">Event</a></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The Mutex class is used to protect a section of code so that at any given time only a single thread can perform the protected operation. Mutex lock for protected access.
<p>
The Mutex can be used as a base class to protect access in a derived class. When used in this manner, the ENTER_CRITICAL and LEAVE_CRITICAL macros can be used to specify when code written for the derived class needs to be protected by the default Mutex of the derived class, and hence is presumed to be 'thread safe' from multiple instance execution. One of the most basic Common C++ synchronization object is the Mutex class. A Mutex only allows one thread to continue execution at a given time over a specific section of code. Mutex's have a enter and leave method; only one thread can continue from the Enter until the Leave is called. The next thread waiting can then get through. Mutex's are also known as "CRITICAL SECTIONS" in win32-speak.
<p>
The Mutex is always recursive in that if the same thread invokes the same mutex lock multiple times, it must release it multiple times. This allows a function to call another function which also happens to use the same mutex lock when called directly. This was deemed essential because a mutex might be used to block individual file requests in say, a database, but the same mutex might be needed to block a whole series of database updates that compose a "transaction" for one thread to complete together without having to write alternate non-locking member functions to invoke for each part of a transaction.
<p>
Strangely enough, the original pthread draft standard does not directly support recursive mutexes. In fact this is the most common "NP" extension for most pthread implementations. Common C++ emulates recursive mutex behavior when the target platform does not directly support it.
<p>
In addition to the Mutex, Common C++ supports a rwlock class. This implements the X/Open recommended "rwlock". On systems which do not support rwlock's, the behavior is emulated with a Mutex; however, the advantage of a rwlock over a mutex is then entirely lost. There has been some suggested clever hacks for "emulating" the behavior of a rwlock with a pair of mutexes and a semaphore, and one of these will be adapted for Common C++ in the future for platforms that do not support rwlock's directly.
<p>
<dl compact><dt><b>
Author: </b><dd>
David Sugar &lt;<a href="mailto:dyfet@ostel.com">dyfet@ostel.com</a>&gt; </dl>
<p>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a name="a0" doxytag="Mutex::Mutex"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> Mutex::Mutex </td>
          <td class="md">(&nbsp;</td>
          <td class="mdname1">&nbsp;          </td>
          <td class="md">)&nbsp;</td>
          <td class="md"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
The mutex is always initialized as a recursive entity.
<p>
    </td>
  </tr>
</table>
<a name="a1" doxytag="Mutex::~Mutex"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> virtual Mutex::~Mutex </td>
          <td class="md">(&nbsp;</td>
          <td class="mdname1">&nbsp;          </td>
          <td class="md">)&nbsp;</td>
          <td class="md"><code> [virtual]</code></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Destroying the mutex removes any system resources associated with it.
<p>
If a mutex lock is currently in place, it is presumed to terminate when the Mutex is destroyed.     </td>
  </tr>
</table>
<hr><h2>Member Function Documentation</h2>
<a name="a2" doxytag="Mutex::EnterMutex"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> void Mutex::EnterMutex </td>
          <td class="md">(&nbsp;</td>
          <td class="md">void</td>
          <td class="mdname1">&nbsp;          </td>
          <td class="md">)&nbsp;</td>
          <td class="md"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Entering a Mutex locks the mutex for the current thread.
<p>
This also can be done using the ENTER_CRITICAL macro or by using the ++ operator on a mutex.
<p>
<dl compact><dt><b>
See also: </b><dd>
<a class="el" href="class_mutex.html#a4">LeaveMutex</a> </dl>    </td>
  </tr>
</table>
<a name="a4" doxytag="Mutex::LeaveMutex"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> void Mutex::LeaveMutex </td>
          <td class="md">(&nbsp;</td>
          <td class="md">void</td>
          <td class="mdname1">&nbsp;          </td>
          <td class="md">)&nbsp;</td>
          <td class="md"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Leaving a mutex frees that mutex for use by another thread.
<p>
If the mutex has been entered (invoked) multiple times (recursivily) by the same thread, then it will need to be exited the same number of instances before it is free for re-use. This operation can also be done using the LEAVE_CRITICAL macro or by the -- operator on a mutex.
<p>
<dl compact><dt><b>
See also: </b><dd>
<a class="el" href="class_mutex.html#a2">EnterMutex</a> </dl>    </td>
  </tr>
</table>
<a name="a3" doxytag="Mutex::TryEnterMutex"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> bool Mutex::TryEnterMutex </td>
          <td class="md">(&nbsp;</td>
          <td class="md">void</td>
          <td class="mdname1">&nbsp;          </td>
          <td class="md">)&nbsp;</td>
          <td class="md"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Tries to lock the mutex for the current thread.
<p>
Behaves like <a class="el" href="class_mutex.html#a2">EnterMutex</a> , except that it doesn't block the calling thread if the mutex is already locked by another thread.
<p>
<dl compact><dt><b>
Returns: </b><dd>
true if locking the mutex was succesful otherwise false</dl><dl compact><dt><b>
See also: </b><dd>
<a class="el" href="class_mutex.html#a2">EnterMutex</a> , <a class="el" href="class_mutex.html#a4">LeaveMutex</a> </dl>    </td>
  </tr>
</table>
<hr><h2>Friends And Related Function Documentation</h2>
<a name="l0" doxytag="Mutex::Conditional"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> friend class Conditional<code> [friend]</code>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
    </td>
  </tr>
</table>
<a name="l1" doxytag="Mutex::Event"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> friend class Event<code> [friend]</code>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
    </td>
  </tr>
</table>
<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></ul>
<hr><address><small>Generated at Tue Nov 20 13:28:48 2001 for CommonC++ by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.10 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2001</small></address>
</body>
</html>