Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > by-pkgid > ad1ba1135a9c9eeffc2e538163e00373 > files > 716

libCommonC++2_1.4-devel-1.4.1-1mdv2007.0.i586.rpm

\section{ost::Mutex Class Reference}
\label{classost_1_1_mutex}\index{ost::Mutex@{ost::Mutex}}
The {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_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.  


{\tt \#include $<$thread.h$>$}

Inheritance diagram for ost::Mutex::\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=9cm]{classost_1_1_mutex}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf Mutex} (const char $\ast$name=NULL)
\begin{CompactList}\small\item\em The mutex is always initialized as a recursive entity. \item\end{CompactList}\item 
virtual {\bf $\sim$Mutex} ()
\begin{CompactList}\small\item\em Destroying the mutex removes any system resources associated with it. \item\end{CompactList}\item 
void {\bf name\-Mutex} (const char $\ast$name)
\begin{CompactList}\small\item\em Enable setting of mutex name for deadlock debug. \item\end{CompactList}\item 
void {\bf enter\-Mutex} (void)
\begin{CompactList}\small\item\em Entering a {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_mutex})} locks the mutex for the current thread. \item\end{CompactList}\item 
void {\bf enter} (void)
\begin{CompactList}\small\item\em Future abi will use enter/leave/test members. \item\end{CompactList}\item 
void {\bf leave} (void)
\begin{CompactList}\small\item\em Future abi will use enter/leave/test members. \item\end{CompactList}\item 
bool {\bf test} (void)
\begin{CompactList}\small\item\em Future abi will use enter/leave/test members. \item\end{CompactList}\item 
bool {\bf try\-Enter\-Mutex} (void)
\begin{CompactList}\small\item\em Tries to lock the mutex for the current thread. \item\end{CompactList}\item 
void {\bf leave\-Mutex} (void)
\begin{CompactList}\small\item\em Leaving a mutex frees that mutex for use by another thread. \item\end{CompactList}\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
static void {\bf set\-Debug} (bool mode)
\begin{CompactList}\small\item\em Enable or disable deadlock debugging. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
The {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_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. 

The {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_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 {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_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 {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_mutex})} class. A {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_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 \char`\"{}CRITICAL SECTIONS\char`\"{} in win32-speak.

The {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_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 \char`\"{}transaction\char`\"{} for one thread to complete together without having to write alternate non-locking member functions to invoke for each part of a transaction.

Strangely enough, the original pthread draft standard does not directly support recursive mutexes. In fact this is the most common \char`\"{}NP\char`\"{} extension for most pthread implementations. Common C++ emulates recursive mutex behavior when the target platform does not directly support it.

In addition to the {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_mutex})}, Common C++ supports a rwlock class. This implements the X/Open recommended \char`\"{}rwlock\char`\"{}. On systems which do not support rwlock's, the behavior is emulated with a {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_mutex})}; however, the advantage of a rwlock over a mutex is then entirely lost. There has been some suggested clever hacks for \char`\"{}emulating\char`\"{} 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.

\begin{Desc}
\item[Author:]David Sugar $<${\tt dyfet@ostel.com}$>$ \end{Desc}
\begin{Desc}
\item[Examples: ]\par


{\bf tcpservice.cpp}, and {\bf tcpthread.cpp}.\end{Desc}




\subsection{Constructor \& Destructor Documentation}
\index{ost::Mutex@{ost::Mutex}!Mutex@{Mutex}}
\index{Mutex@{Mutex}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}ost::Mutex::Mutex (const char $\ast$ {\em name} = {\tt NULL})}\label{classost_1_1_mutex_22e6ce5d9d8d209dac70e39310459202}


The mutex is always initialized as a recursive entity. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]of mutex for optional deadlock detection \end{description}
\end{Desc}
\index{ost::Mutex@{ost::Mutex}!~Mutex@{$\sim$Mutex}}
\index{~Mutex@{$\sim$Mutex}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual ost::Mutex::$\sim$Mutex ()\hspace{0.3cm}{\tt  [virtual]}}\label{classost_1_1_mutex_5ccc1c2e7278d8adc47fd728706c33a8}


Destroying the mutex removes any system resources associated with it. 

If a mutex lock is currently in place, it is presumed to terminate when the {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_mutex})} is destroyed. 

\subsection{Member Function Documentation}
\index{ost::Mutex@{ost::Mutex}!enter@{enter}}
\index{enter@{enter}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Mutex::enter (void)\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_mutex_ecb516325583e432bf2bf7e4b565f6f6}


Future abi will use enter/leave/test members. 

\index{ost::Mutex@{ost::Mutex}!enterMutex@{enterMutex}}
\index{enterMutex@{enterMutex}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Mutex::enter\-Mutex (void)}\label{classost_1_1_mutex_dc1471d0c2114e5c49e1fe7152448378}


Entering a {\bf Mutex}{\rm (p.\,\pageref{classost_1_1_mutex})} locks the mutex for the current thread. 

This also can be done using the ENTER\_\-CRITICAL macro or by using the ++ operator on a mutex.

\begin{Desc}
\item[See also:]{\bf leave\-Mutex}{\rm (p.\,\pageref{classost_1_1_mutex_403208d275c4c7b8087a40259b0cb0f3})} \end{Desc}
\index{ost::Mutex@{ost::Mutex}!leave@{leave}}
\index{leave@{leave}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Mutex::leave (void)\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_mutex_b6aaecac9c95d31a5862014d7f1afe73}


Future abi will use enter/leave/test members. 

\index{ost::Mutex@{ost::Mutex}!leaveMutex@{leaveMutex}}
\index{leaveMutex@{leaveMutex}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Mutex::leave\-Mutex (void)}\label{classost_1_1_mutex_403208d275c4c7b8087a40259b0cb0f3}


Leaving a mutex frees that mutex for use by another thread. 

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.

\begin{Desc}
\item[See also:]{\bf enter\-Mutex}{\rm (p.\,\pageref{classost_1_1_mutex_dc1471d0c2114e5c49e1fe7152448378})} \end{Desc}
\index{ost::Mutex@{ost::Mutex}!nameMutex@{nameMutex}}
\index{nameMutex@{nameMutex}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Mutex::name\-Mutex (const char $\ast$ {\em name})\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_mutex_bed8b05b63f9cdd2c9ca1f92081b1a8a}


Enable setting of mutex name for deadlock debug. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]for mutex. \end{description}
\end{Desc}
\index{ost::Mutex@{ost::Mutex}!setDebug@{setDebug}}
\index{setDebug@{setDebug}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static void ost::Mutex::set\-Debug (bool {\em mode})\hspace{0.3cm}{\tt  [inline, static]}}\label{classost_1_1_mutex_83b66f786e344b5192a3993d319aa735}


Enable or disable deadlock debugging. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mode}]debug mode. \end{description}
\end{Desc}
\index{ost::Mutex@{ost::Mutex}!test@{test}}
\index{test@{test}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool ost::Mutex::test (void)\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_mutex_c1ff5454b2c9b55790c4bf33f751704c}


Future abi will use enter/leave/test members. 

\begin{Desc}
\item[Returns:]true if entered. \end{Desc}
\index{ost::Mutex@{ost::Mutex}!tryEnterMutex@{tryEnterMutex}}
\index{tryEnterMutex@{tryEnterMutex}!ost::Mutex@{ost::Mutex}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool ost::Mutex::try\-Enter\-Mutex (void)}\label{classost_1_1_mutex_a46b490ac92017ef89980b0020bff8c0}


Tries to lock the mutex for the current thread. 

Behaves like {\bf enter\-Mutex}{\rm (p.\,\pageref{classost_1_1_mutex_dc1471d0c2114e5c49e1fe7152448378})} , except that it doesn't block the calling thread if the mutex is already locked by another thread.

\begin{Desc}
\item[Returns:]true if locking the mutex was succesful otherwise false\end{Desc}
\begin{Desc}
\item[See also:]{\bf enter\-Mutex}{\rm (p.\,\pageref{classost_1_1_mutex_dc1471d0c2114e5c49e1fe7152448378})} 

{\bf leave\-Mutex}{\rm (p.\,\pageref{classost_1_1_mutex_403208d275c4c7b8087a40259b0cb0f3})} \end{Desc}


The documentation for this class was generated from the following file:\begin{CompactItemize}
\item 
{\bf thread.h}\end{CompactItemize}