Sophie

Sophie

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

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

\section{ost::Thread Class Reference}
\label{classost_1_1_thread}\index{ost::Thread@{ost::Thread}}
Every thread of execution in an application is created by instantiating an object of a class derived from the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} class.base class used to derive all threads of execution.  


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

Inheritance diagram for ost::Thread::\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=1.29032cm]{classost_1_1_thread}
\end{center}
\end{figure}
\subsection*{Public Types}
\begin{CompactItemize}
\item 
typedef enum {\bf ost::Thread::Throw} {\bf Throw}
\begin{CompactList}\small\item\em How to raise error. \item\end{CompactList}\item 
typedef enum {\bf ost::Thread::Cancel} {\bf Cancel}
\begin{CompactList}\small\item\em How work cancellation. \item\end{CompactList}\item 
typedef enum {\bf ost::Thread::Suspend} {\bf Suspend}
\begin{CompactList}\small\item\em How work suspend. \item\end{CompactList}\item 
enum {\bf Throw} \{ {\bf throw\-Nothing}, 
{\bf throw\-Object}, 
{\bf throw\-Exception}
 \}
\begin{CompactList}\small\item\em How to raise error. \item\end{CompactList}\item 
enum {\bf Cancel} \{ \par
{\bf cancel\-Initial} = 0, 
{\bf cancel\-Deferred} = 1, 
{\bf cancel\-Immediate}, 
{\bf cancel\-Disabled}, 
\par
{\bf cancel\-Manual}, 
{\bf cancel\-Default} = cancel\-Deferred
 \}
\begin{CompactList}\small\item\em How work cancellation. \item\end{CompactList}\item 
enum {\bf Suspend} \{ {\bf suspend\-Enable}, 
{\bf suspend\-Disable}
 \}
\begin{CompactList}\small\item\em How work suspend. \item\end{CompactList}\end{CompactItemize}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf Thread} (bool is\-Main)
\begin{CompactList}\small\item\em This is actually a special constructor that is used to create a thread \char`\"{}object\char`\"{} for the current execution context when that context is not created via an instance of a derived {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} object itself. \item\end{CompactList}\item 
{\bf Thread} (int pri=0, size\_\-t stack=0)
\begin{CompactList}\small\item\em When a thread object is contructed, a new thread of execution context is created. \item\end{CompactList}\item 
{\bf Thread} (const {\bf Thread} \&th)
\begin{CompactList}\small\item\em A thread of execution can also be specified by cloning an existing thread. \item\end{CompactList}\item 
virtual {\bf $\sim$Thread} ()
\begin{CompactList}\small\item\em The thread destructor should clear up any resources that have been allocated by the thread. \item\end{CompactList}\item 
int {\bf start} ({\bf Semaphore} $\ast$start=0)
\begin{CompactList}\small\item\em When a new thread is created, it does not begin immediate execution. \item\end{CompactList}\item 
int {\bf detach} ({\bf Semaphore} $\ast$start=0)
\begin{CompactList}\small\item\em Start a new thread as \char`\"{}detached\char`\"{}. \item\end{CompactList}\item 
{\bf Thread} $\ast$ {\bf get\-Parent} (void)
\begin{CompactList}\small\item\em Gets the pointer to the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} class which created the current thread object. \item\end{CompactList}\item 
void {\bf suspend} (void)
\begin{CompactList}\small\item\em Suspends execution of the selected thread. \item\end{CompactList}\item 
void {\bf resume} (void)
\begin{CompactList}\small\item\em Resumes execution of the selected thread. \item\end{CompactList}\item 
{\bf Cancel} {\bf get\-Cancel} (void)
\begin{CompactList}\small\item\em Used to retrieve the cancellation mode in effect for the selected thread. \item\end{CompactList}\item 
bool {\bf is\-Running} (void)
\begin{CompactList}\small\item\em Verifies if the thread is still running or has already been terminated but not yet deleted. \item\end{CompactList}\item 
bool {\bf is\-Detached} (void)
\begin{CompactList}\small\item\em Check if this thread is detached. \item\end{CompactList}\item 
void {\bf join} (void)
\begin{CompactList}\small\item\em Blocking call which unlocks when thread terminates. \item\end{CompactList}\item 
bool {\bf is\-Thread} (void)
\begin{CompactList}\small\item\em Tests to see if the current execution context is the same as the specified thread object. \item\end{CompactList}\item 
{\bf cctid\_\-t} {\bf get\-Id} (void) const 
\begin{CompactList}\small\item\em Get system thread numeric identifier. \item\end{CompactList}\item 
const char $\ast$ {\bf get\-Name} (void)
\begin{CompactList}\small\item\em Get the name string for this thread, to use in debug messages. \item\end{CompactList}\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
static {\bf Thread} $\ast$ {\bf get} (void)
\item 
static void {\bf set\-Stack} (size\_\-t size=0)
\begin{CompactList}\small\item\em Set base stack limit before manual stack sizes have effect. \item\end{CompactList}\item 
static void {\bf sleep} ({\bf timeout\_\-t} msec)
\begin{CompactList}\small\item\em A thread-safe sleep call. \item\end{CompactList}\item 
static void {\bf yield} (void)
\begin{CompactList}\small\item\em Yields the current thread's CPU time slice to allow another thread to begin immediate execution. \item\end{CompactList}\item 
static {\bf Throw} {\bf get\-Exception} (void)
\begin{CompactList}\small\item\em Get exception mode of the current thread. \item\end{CompactList}\item 
static void {\bf set\-Exception} ({\bf Throw} mode)
\begin{CompactList}\small\item\em Set exception mode of the current thread. \item\end{CompactList}\item 
static {\bf Cancel} {\bf enter\-Cancel} (void)
\begin{CompactList}\small\item\em This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't. \item\end{CompactList}\item 
static void {\bf exit\-Cancel} ({\bf Cancel} cancel)
\begin{CompactList}\small\item\em This is used to restore a cancel block. \item\end{CompactList}\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
void {\bf set\-Name} (const char $\ast$text)
\begin{CompactList}\small\item\em Set the name of the current thread. \item\end{CompactList}\item 
virtual void {\bf run} (void)=0
\begin{CompactList}\small\item\em All threads execute by deriving the Run method of {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})}. \item\end{CompactList}\item 
virtual void {\bf final} (void)
\begin{CompactList}\small\item\em A thread that is self terminating, either by invoking {\bf exit()}{\rm (p.\,\pageref{classost_1_1_thread_cd315d7c877b346970680d739da3e994})} or leaving it's {\bf run()}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})}, will have this method called. \item\end{CompactList}\item 
virtual void {\bf initial} (void)
\begin{CompactList}\small\item\em The initial method is called by a newly created thread when it starts execution. \item\end{CompactList}\item 
virtual void $\ast$ {\bf get\-Extended} (void)
\begin{CompactList}\small\item\em Since {\bf get\-Parent()}{\rm (p.\,\pageref{classost_1_1_thread_ac5bc230c3bad5c837baa9e6d01f4c24})} and {\bf get\-Thread()}{\rm (p.\,\pageref{namespaceost_99c7f7d02b00922b0f5ee62fc3bb75fd})} only refer to an object of the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} \char`\"{}base\char`\"{} type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by {\bf get\-Parent()}{\rm (p.\,\pageref{classost_1_1_thread_ac5bc230c3bad5c837baa9e6d01f4c24})} and {\bf get\-Thread()}{\rm (p.\,\pageref{namespaceost_99c7f7d02b00922b0f5ee62fc3bb75fd})}. \item\end{CompactList}\item 
virtual void {\bf notify} ({\bf Thread} $\ast$)
\begin{CompactList}\small\item\em When a thread terminates, it now sends a notification message to the parent thread which created it. \item\end{CompactList}\item 
void {\bf exit} (void)
\begin{CompactList}\small\item\em Used to properly exit from a {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} derived {\bf run()}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})} or {\bf initial()}{\rm (p.\,\pageref{classost_1_1_thread_300c229e76725eeddc69867f7ecea91f})} method. \item\end{CompactList}\item 
void {\bf sync} (void)
\begin{CompactList}\small\item\em Used to wait for a join or cancel, in place of explicit exit. \item\end{CompactList}\item 
bool {\bf test\-Cancel} (void)
\begin{CompactList}\small\item\em test a cancellation point for deferred thread cancellation. \item\end{CompactList}\item 
void {\bf set\-Cancel} ({\bf Cancel} mode)
\begin{CompactList}\small\item\em Sets thread cancellation mode. \item\end{CompactList}\item 
void {\bf set\-Suspend} ({\bf Suspend} mode)
\begin{CompactList}\small\item\em Sets the thread's ability to be suspended from execution. \item\end{CompactList}\item 
void {\bf terminate} (void)
\begin{CompactList}\small\item\em Used by another thread to terminate the current thread. \item\end{CompactList}\item 
void {\bf clr\-Parent} (void)
\begin{CompactList}\small\item\em clear parent thread relationship. \item\end{CompactList}\end{CompactItemize}
\subsection*{Friends}
\begin{CompactItemize}
\item 
class {\bf Posix\-Thread}
\item 
class {\bf Dummy\-Thread}
\item 
class {\bf Cancellation}
\item 
class {\bf postream\_\-type}
\item 
class {\bf Slog}
\item 
class {\bf Thread\-Impl}
\item 
void {\bf operator++} ({\bf Thread} \&th)
\begin{CompactList}\small\item\em Signal the semaphore that the specified thread is waiting for before beginning execution. \item\end{CompactList}\item 
void {\bf operator--} ({\bf Thread} \&th)
\end{CompactItemize}


\subsection{Detailed Description}
Every thread of execution in an application is created by instantiating an object of a class derived from the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} class.base class used to derive all threads of execution. 

Classes derived from {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} must implement the {\bf run()}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})} method, which specifies the code of the thread. The base {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} class supports encapsulation of the generic threading methods implemented on various target operating systems. This includes the ability to start and stop threads in a synchronized and controllable manner, the ability to specify thread execution priority, and thread specific \char`\"{}system call\char`\"{} wrappers, such as for sleep and yield. A thread exception is thrown if the thread cannot be created. Threading was the first part of Common C++ I wrote, back when it was still the APE library. My goal for Common C++ threading has been to make threading as natural and easy to use in C++ application development as threading is in Java. With this said, one does not need to use threading at all to take advantage of Common C++. However, all Common C++ classes are designed at least to be thread-aware/thread-safe as appropriate and necessary.

Common C++ threading is currently built either from the Posix \char`\"{}pthread\char`\"{} library or using the win32 SDK. In that the Posix \char`\"{}pthread\char`\"{} draft has gone through many revisions, and many system implementations are only marginally compliant, and even then usually in different ways, I wrote a large series of autoconf macros found in ost\_\-pthread.m4 which handle the task of identifying which pthread features and capabilities your target platform supports. In the process I learned much about what autoconf can and cannot do for you..

Currently the GNU Portable {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} library (GNU pth) is not directly supported in Common C++. While GNU \char`\"{}Pth\char`\"{} doesn't offer direct native threading support or benefit from SMP hardware, many of the design advantages of threading can be gained from it's use, and the Pth pthread \char`\"{}emulation\char`\"{} library should be usable with Common C++. In the future, Common C++ will directly support Pth, as well as OS/2 and Be\-OS native threading API's.

Common C++ itself defines a fairly \char`\"{}neutral\char`\"{} threading model that is not tied to any specific API such as pthread, win32, etc. This neutral thread model is contained in a series of classes which handle threading and synchronization and which may be used together to build reliable threaded applications.

Common C++ defines application specific threads as objects which are derived from the Common C++ \char`\"{}Thread\char`\"{} base class. At minimum the \char`\"{}Run\char`\"{} method must be implemented, and this method essentially is the \char`\"{}thread\char`\"{}, for it is executed within the execution context of the thread, and when the Run method terminates the thread is assumed to have terminated.

Common C++ allows one to specify the running priority of a newly created thread relative to the \char`\"{}parent\char`\"{} thread which is the thread that is executing when the constructor is called. Since most newer C++ implementations do not allow one to call virtual constructors or virtual methods from constructors, the thread must be \char`\"{}started\char`\"{} after the constructor returns. This is done either by defining a \char`\"{}starting\char`\"{} semaphore object that one or more newly created thread objects can wait upon, or by invoking an explicit \char`\"{}start\char`\"{} member function.

Threads can be \char`\"{}suspended\char`\"{} and \char`\"{}resumed\char`\"{}. As this behavior is not defined in the Posix \char`\"{}pthread\char`\"{} specification, it is often emulated through signals. Typically SIGUSR1 will be used for this purpose in Common C++ applications, depending in the target platform. On Linux, since threads are indeed processes, SIGSTP and SIGCONT can be used. On solaris, the Solaris thread library supports suspend and resume directly.

Threads can be canceled. Not all platforms support the concept of externally cancelable threads. On those platforms and API implementations that do not, threads are typically canceled through the action of a signal handler.

As noted earlier, threads are considered running until the \char`\"{}Run\char`\"{} method returns, or until a cancellation request is made. Common C++ threads can control how they respond to cancellation, using set\-Cancellation(). {\bf Cancellation}{\rm (p.\,\pageref{classost_1_1_cancellation})} requests can be ignored, set to occur only when a cancellation \char`\"{}point\char`\"{} has been reached in the code, or occur immediately. Threads can also exit by returning from Run() or by invoking the Exit() method.

Generally it is a good practice to initialize any resources the thread may require within the constructor of your derived thread class, and to purge or restore any allocated resources in the destructor. In most cases, the destructor will be executed after the thread has terminated, and hence will execute within the context of the thread that requested a join rather than in the context of the thread that is being terminated. Most destructors in derived thread classes should first call Terminate() to make sure the thread has stopped running before releasing resources.

A Common C++ thread is normally canceled by deleting the thread object. The process of deletion invokes the thread's destructor, and the destructor will then perform a \char`\"{}join\char`\"{} against the thread using the Terminate() function. This behavior is not always desirable since the thread may block itself from cancellation and block the current \char`\"{}delete\char`\"{} operation from completing. One can alternately invoke Terminate() directly before deleting a thread object.

When a given Common C++ thread exits on it's own through it's Run() method, a \char`\"{}Final\char`\"{} method will be called. This Final method will be called while the thread is \char`\"{}detached\char`\"{}. If a thread object is constructed through a \char`\"{}new\char`\"{} operator, it's final method can be used to \char`\"{}self delete\char`\"{} when done, and allows an independent thread to construct and remove itself autonomously.

A special global function, {\bf get\-Thread()}{\rm (p.\,\pageref{namespaceost_99c7f7d02b00922b0f5ee62fc3bb75fd})}, is provided to identify the thread object that represents the current execution context you are running under. This is sometimes needed to deliver signals to the correct thread. Since all thread manipulation should be done through the Common C++ (base) thread class itself, this provides the same functionality as things like \char`\"{}pthread\_\-self\char`\"{} for Common C++.

All Common C++ threads have an exception \char`\"{}mode\char`\"{} which determines their behavior when an exception is thrown by another Common C++ class. Extensions to Common C++ should respect the current exception mode and use {\bf get\-Exception()}{\rm (p.\,\pageref{classost_1_1_thread_0272b6a8de586ee5ee2464bbdb030392})} to determine what to do when they are about to throw an object. The default exception mode (defined in the Thread() constructor) is throw\-Object, which causes a pointer to an instance of the class where the error occured to be thrown. Other exception modes are throw\-Exception, which causes a class-specific exception class to be thrown, and throw\-Nothing, which causes errors to be ignored.

As an example, you could try to call the {\bf Socket}{\rm (p.\,\pageref{classost_1_1_socket})} class with an invalid address that the system could not bind to. This would cause an object of type {\bf Socket}{\rm (p.\,\pageref{classost_1_1_socket})} $\ast$ to be thrown by default, as the default exception mode is throw\-Object. If you call set\-Exception(throw\-Exception) before the bad call to the {\bf Socket}{\rm (p.\,\pageref{classost_1_1_socket})} constructor, an object of type Sock\-Exception (the exception class for class {\bf Socket}{\rm (p.\,\pageref{classost_1_1_socket})}) will be thrown instead.

To determine what exception class is thrown by a given Common C++ class when the exception mode is set to throw\-Exception, search the source files for the class you are interested in for a class which inherits directly or indirectly from class Exception. This is the exception class which would be thrown when the exception mode is set to throw\-Exception.

The advantage of using throw\-Exception versus throw\-Object is that more information is available to the programmer from the thrown object. All class-specific exceptions inherit from class Exception, which provides a get\-String() method which can be called to get a human-readable error string.

Common C++ threads are often aggregated into other classes to provide services that are \char`\"{}managed\char`\"{} from or operate within the context of a thread, even within the Common C++ framework itself. A good example of this is the {\bf TCPSession}{\rm (p.\,\pageref{classost_1_1_t_c_p_session})} class, which essentially is a combination of a TCP client connection and a separate thread the user can define by deriving a class with a Run() method to handle the connected service. This aggregation logically connects the successful allocation of a given resource with the construction of a thread to manage and perform operations for said resource.

Threads are also used in \char`\"{}service pools\char`\"{}. In Common C++, a service pool is one or more threads that are used to manage a set of resources. While Common C++ does not provide a direct \char`\"{}pool\char`\"{} class, it does provide a model for their implementation, usually by constructing an array of thread \char`\"{}service\char`\"{} objects, each of which can then be assigned the next new instance of a given resource in turn or algorithmically.

Threads have signal handlers associated with them. Several signal types are \char`\"{}predefined\char`\"{} and have special meaning. All signal handlers are defined as virtual member functions of the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} class which are called when a specific signal is received for a given thread. The \char`\"{}SIGPIPE\char`\"{} event is defined as a \char`\"{}Disconnect\char`\"{} event since it's normally associated with a socket disconnecting or broken fifo. The Hangup() method is associated with the SIGHUP signal. All other signals are handled through the more generic Signal().

Incidently, unlike Posix, the win32 API has no concept of signals, and certainly no means to define or deliver signals on a per-thread basis. For this reason, no signal handling is supported or emulated in the win32 implementation of Common C++ at this time.

In addition to {\bf TCPStream}{\rm (p.\,\pageref{classost_1_1_t_c_p_stream})}, there is a {\bf TCPSession}{\rm (p.\,\pageref{classost_1_1_t_c_p_session})} class which combines a thread with a {\bf TCPStream}{\rm (p.\,\pageref{classost_1_1_t_c_p_stream})} object. The assumption made by {\bf TCPSession}{\rm (p.\,\pageref{classost_1_1_t_c_p_session})} is that one will service each TCP connection with a separate thread, and this makes sense for systems where extended connections may be maintained and complex protocols are being used over TCP.

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


{\bf bug1.cpp}, {\bf bug2.cpp}, {\bf tcpservice.cpp}, {\bf tcpstr1.cpp}, {\bf thread1.cpp}, and {\bf thread2.cpp}.\end{Desc}




\subsection{Member Typedef Documentation}
\index{ost::Thread@{ost::Thread}!Cancel@{Cancel}}
\index{Cancel@{Cancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}typedef enum {\bf ost::Thread::Cancel}  {\bf ost::Thread::Cancel}}\label{classost_1_1_thread_0d876c60edcf92d3d96121aacea441d0}


How work cancellation. 

\index{ost::Thread@{ost::Thread}!Suspend@{Suspend}}
\index{Suspend@{Suspend}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}typedef enum {\bf ost::Thread::Suspend}  {\bf ost::Thread::Suspend}}\label{classost_1_1_thread_81069ba4a0bf16a0aa9f076aa725f0c1}


How work suspend. 

\index{ost::Thread@{ost::Thread}!Throw@{Throw}}
\index{Throw@{Throw}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}typedef enum {\bf ost::Thread::Throw}  {\bf ost::Thread::Throw}}\label{classost_1_1_thread_511f08b9f1aef08b4f02e2ad225960ab}


How to raise error. 



\subsection{Member Enumeration Documentation}
\index{ost::Thread@{ost::Thread}!Cancel@{Cancel}}
\index{Cancel@{Cancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf ost::Thread::Cancel}}\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69b}


How work cancellation. 

\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{cancelInitial@{cancelInitial}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!cancelInitial@{cancelInitial}}\item[{\em 
cancel\-Initial\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69bbbf14157c17311ec31f0967032ecb357}
}]used internally, do not use \index{cancelDeferred@{cancelDeferred}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!cancelDeferred@{cancelDeferred}}\item[{\em 
cancel\-Deferred\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69bb02b8cd8d899a693e8cbb86082f4ef16}
}]exit thread on cancellation pointsuch as yield \index{cancelImmediate@{cancelImmediate}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!cancelImmediate@{cancelImmediate}}\item[{\em 
cancel\-Immediate\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69b57f820ea4f7a326c27cc504a213e167d}
}]exit befor cancellation \index{cancelDisabled@{cancelDisabled}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!cancelDisabled@{cancelDisabled}}\item[{\em 
cancel\-Disabled\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69be07cc9f6d3d7333c8cce543a8bb58215}
}]ignore cancellation \index{cancelManual@{cancelManual}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!cancelManual@{cancelManual}}\item[{\em 
cancel\-Manual\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69ba194b63cafc5387684afe7943fe3b5f0}
}]unimplemented (working in progress) 

\begin{Desc}
\item[{\bf Todo}]implement \end{Desc}
\index{cancelDefault@{cancelDefault}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!cancelDefault@{cancelDefault}}\item[{\em 
cancel\-Default\label{classost_1_1_thread_24f333b09607b7c48a97e05865ada69bdf753e6d700f194c1b8f695a9bd67554}
}]default you should use this for compatibility instead of deferred \end{description}
\end{Desc}

\index{ost::Thread@{ost::Thread}!Suspend@{Suspend}}
\index{Suspend@{Suspend}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf ost::Thread::Suspend}}\label{classost_1_1_thread_ff7bd364ce645eac95affbf74f1a7087}


How work suspend. 

\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{suspendEnable@{suspendEnable}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!suspendEnable@{suspendEnable}}\item[{\em 
suspend\-Enable\label{classost_1_1_thread_ff7bd364ce645eac95affbf74f1a708727f2f61f4bc18b64e9c25f73bb008a38}
}]suspend enabled \index{suspendDisable@{suspendDisable}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!suspendDisable@{suspendDisable}}\item[{\em 
suspend\-Disable\label{classost_1_1_thread_ff7bd364ce645eac95affbf74f1a70870e9f14f0e69d8c12c36a46d108a5074b}
}]suspend disabled, Suspend do nothing \end{description}
\end{Desc}

\index{ost::Thread@{ost::Thread}!Throw@{Throw}}
\index{Throw@{Throw}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf ost::Thread::Throw}}\label{classost_1_1_thread_b9538e839c06104af2974b77d2a5674d}


How to raise error. 

\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{throwNothing@{throwNothing}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!throwNothing@{throwNothing}}\item[{\em 
throw\-Nothing\label{classost_1_1_thread_b9538e839c06104af2974b77d2a5674d1b058025329425c90f383d124ee605e5}
}]continue without throwing error \index{throwObject@{throwObject}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!throwObject@{throwObject}}\item[{\em 
throw\-Object\label{classost_1_1_thread_b9538e839c06104af2974b77d2a5674dea5957cd08cfecf17f366352bcf9ad80}
}]throw object that cause error (throw this) \index{throwException@{throwException}!ost::Thread@{ost::Thread}}\index{ost::Thread@{ost::Thread}!throwException@{throwException}}\item[{\em 
throw\-Exception\label{classost_1_1_thread_b9538e839c06104af2974b77d2a5674d8e51a6870e65238764becffff92d7f54}
}]throw an object relative to error \end{description}
\end{Desc}



\subsection{Constructor \& Destructor Documentation}
\index{ost::Thread@{ost::Thread}!Thread@{Thread}}
\index{Thread@{Thread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}ost::Thread::Thread (bool {\em is\-Main})}\label{classost_1_1_thread_72470c1b00d098e74162284e248c0435}


This is actually a special constructor that is used to create a thread \char`\"{}object\char`\"{} for the current execution context when that context is not created via an instance of a derived {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} object itself. 

This constructor does not support First.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em is\-Main}]bool used if the main \char`\"{}thread\char`\"{} of the application. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!Thread@{Thread}}
\index{Thread@{Thread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}ost::Thread::Thread (int {\em pri} = {\tt 0}, size\_\-t {\em stack} = {\tt 0})}\label{classost_1_1_thread_082ea94f104219969a2d75becc749af6}


When a thread object is contructed, a new thread of execution context is created. 

This constructor allows basic properties of that context (thread priority, stack space, etc) to be defined. The starting condition is also specified for whether the thread is to wait on a semaphore before begining execution or wait until it's start method is called.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em pri}]thread base priority relative to it's parent. \item[{\em stack}]space as needed in some implementations. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!Thread@{Thread}}
\index{Thread@{Thread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}ost::Thread::Thread (const {\bf Thread} \& {\em th})}\label{classost_1_1_thread_0ba7f4211aabb5a278c546d0fae81f55}


A thread of execution can also be specified by cloning an existing thread. 

The existing thread's properties (cancel mode, priority, etc), are also duplicated.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em th}]currently executing thread object to clone. \end{description}
\end{Desc}
\begin{Desc}
\item[{\bf Todo}]implement in win32 \end{Desc}
\index{ost::Thread@{ost::Thread}!~Thread@{$\sim$Thread}}
\index{~Thread@{$\sim$Thread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual ost::Thread::$\sim$Thread ()\hspace{0.3cm}{\tt  [virtual]}}\label{classost_1_1_thread_d363397f26006af68fa9315c9bff8589}


The thread destructor should clear up any resources that have been allocated by the thread. 

The desctructor of a derived thread should begin with Terminate() and is presumed to then execute within the context of the thread causing terminaton. 

\subsection{Member Function Documentation}
\index{ost::Thread@{ost::Thread}!clrParent@{clrParent}}
\index{clrParent@{clrParent}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::clr\-Parent (void)\hspace{0.3cm}{\tt  [inline, protected]}}\label{classost_1_1_thread_5e574c2c5f388277527c9257524dd654}


clear parent thread relationship. 

\index{ost::Thread@{ost::Thread}!detach@{detach}}
\index{detach@{detach}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int ost::Thread::detach ({\bf Semaphore} $\ast$ {\em start} = {\tt 0})}\label{classost_1_1_thread_c30778f0fffd9dd952fd73cb541cc70b}


Start a new thread as \char`\"{}detached\char`\"{}. 

This is an alternative {\bf start()}{\rm (p.\,\pageref{classost_1_1_thread_2ef198d7aefb93cf9de4fcc6b66c27a2})} method that resolves some issues with later glibc implimentations which incorrectly impliment self-detach.

\begin{Desc}
\item[Returns:]error code if execution fails. \end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em start}]optional starting semaphore to alternately use. \end{description}
\end{Desc}
\begin{Desc}
\item[Examples: ]\par
{\bf thread2.cpp}.\end{Desc}
\index{ost::Thread@{ost::Thread}!enterCancel@{enterCancel}}
\index{enterCancel@{enterCancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static {\bf Cancel} ost::Thread::enter\-Cancel (void)\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_599880181a0aeaef8a0ddedeeceddb9a}


This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't. 

\begin{Desc}
\item[Returns:]saved cancel type. \end{Desc}
\index{ost::Thread@{ost::Thread}!exit@{exit}}
\index{exit@{exit}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::exit (void)\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_cd315d7c877b346970680d739da3e994}


Used to properly exit from a {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} derived {\bf run()}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})} or {\bf initial()}{\rm (p.\,\pageref{classost_1_1_thread_300c229e76725eeddc69867f7ecea91f})} method. 

Terminates execution of the current thread and calls the derived classes {\bf final()}{\rm (p.\,\pageref{classost_1_1_thread_6fb521eb3d23c51925472a3fe0abf327})} method. \begin{Desc}
\item[Examples: ]\par
{\bf bug2.cpp}, and {\bf tcpservice.cpp}.\end{Desc}
\index{ost::Thread@{ost::Thread}!exitCancel@{exitCancel}}
\index{exitCancel@{exitCancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static void ost::Thread::exit\-Cancel ({\bf Cancel} {\em cancel})\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_bcad222419e4106ac21ce12605eb4fe7}


This is used to restore a cancel block. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cancel}]type that was saved. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!final@{final}}
\index{final@{final}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual void ost::Thread::final (void)\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classost_1_1_thread_6fb521eb3d23c51925472a3fe0abf327}


A thread that is self terminating, either by invoking {\bf exit()}{\rm (p.\,\pageref{classost_1_1_thread_cd315d7c877b346970680d739da3e994})} or leaving it's {\bf run()}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})}, will have this method called. 

It can be used to self delete the current object assuming the object was created with new on the heap rather than stack local, hence one may often see final defined as \char`\"{}delete this\char`\"{} in a derived thread class. A final method, while running, cannot be terminated or cancelled by another thread. Final is called for all cancellation type (even immediate).

You can safe delete thread (\char`\"{}delete this\char`\"{}) class on final, but you should exit ASAP (or do not try to call Common\-C++ methods...)

\begin{Desc}
\item[Note:]A thread cannot delete its own context or join itself. To make a thread that is a self running object that self-deletes, one has to detach the thread by using {\bf detach()}{\rm (p.\,\pageref{classost_1_1_thread_c30778f0fffd9dd952fd73cb541cc70b})} instead of {\bf start()}{\rm (p.\,\pageref{classost_1_1_thread_2ef198d7aefb93cf9de4fcc6b66c27a2})}.\end{Desc}
\begin{Desc}
\item[See also:]{\bf exit}{\rm (p.\,\pageref{classost_1_1_thread_cd315d7c877b346970680d739da3e994})} 

{\bf run}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})} \end{Desc}
\begin{Desc}
\item[Examples: ]\par
{\bf tcpthread.cpp}.\end{Desc}
\index{ost::Thread@{ost::Thread}!get@{get}}
\index{get@{get}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static {\bf Thread}$\ast$ ost::Thread::get (void)\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_aad41a9f7962bdc3058a429df48246fd}


\index{ost::Thread@{ost::Thread}!getCancel@{getCancel}}
\index{getCancel@{getCancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Cancel} ost::Thread::get\-Cancel (void)\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_thread_3524521d80bcc0562fb59a28ce5d62a4}


Used to retrieve the cancellation mode in effect for the selected thread. 

\begin{Desc}
\item[Returns:]cancellation mode constant. \end{Desc}
\index{ost::Thread@{ost::Thread}!getException@{getException}}
\index{getException@{getException}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static {\bf Throw} ost::Thread::get\-Exception (void)\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_0272b6a8de586ee5ee2464bbdb030392}


Get exception mode of the current thread. 

\begin{Desc}
\item[Returns:]exception mode. \end{Desc}
\index{ost::Thread@{ost::Thread}!getExtended@{getExtended}}
\index{getExtended@{getExtended}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual void$\ast$ ost::Thread::get\-Extended (void)\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classost_1_1_thread_b73c94e3ca46cb24f4246e71fff73026}


Since {\bf get\-Parent()}{\rm (p.\,\pageref{classost_1_1_thread_ac5bc230c3bad5c837baa9e6d01f4c24})} and {\bf get\-Thread()}{\rm (p.\,\pageref{namespaceost_99c7f7d02b00922b0f5ee62fc3bb75fd})} only refer to an object of the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} \char`\"{}base\char`\"{} type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by {\bf get\-Parent()}{\rm (p.\,\pageref{classost_1_1_thread_ac5bc230c3bad5c837baa9e6d01f4c24})} and {\bf get\-Thread()}{\rm (p.\,\pageref{namespaceost_99c7f7d02b00922b0f5ee62fc3bb75fd})}. 

\begin{Desc}
\item[Returns:]pointer to derived class specific data. \end{Desc}
\index{ost::Thread@{ost::Thread}!getId@{getId}}
\index{getId@{getId}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf cctid\_\-t} ost::Thread::get\-Id (void) const}\label{classost_1_1_thread_3947a150139cf226626f47166ff92286}


Get system thread numeric identifier. 

\begin{Desc}
\item[Returns:]numeric identifier of this thread. \end{Desc}
\index{ost::Thread@{ost::Thread}!getName@{getName}}
\index{getName@{getName}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}const char$\ast$ ost::Thread::get\-Name (void)\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_thread_e78f5d3f965bff1b6aa4ae6dacc5cc35}


Get the name string for this thread, to use in debug messages. 

\begin{Desc}
\item[Returns:]debug name. \end{Desc}
\index{ost::Thread@{ost::Thread}!getParent@{getParent}}
\index{getParent@{getParent}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Thread}$\ast$ ost::Thread::get\-Parent (void)\hspace{0.3cm}{\tt  [inline]}}\label{classost_1_1_thread_ac5bc230c3bad5c837baa9e6d01f4c24}


Gets the pointer to the {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} class which created the current thread object. 

\begin{Desc}
\item[Returns:]a {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} $\ast$, or \char`\"{}(Thread $\ast$)this\char`\"{} if no parent. \end{Desc}
\index{ost::Thread@{ost::Thread}!initial@{initial}}
\index{initial@{initial}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual void ost::Thread::initial (void)\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classost_1_1_thread_300c229e76725eeddc69867f7ecea91f}


The initial method is called by a newly created thread when it starts execution. 

This method is ran with deferred cancellation disabled by default. The Initial method is given a separate handler so that it can create temporary objects on it's own stack frame, rather than having objects created on {\bf run()}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})} that are only needed by startup and yet continue to consume stack space.

\begin{Desc}
\item[See also:]{\bf run}{\rm (p.\,\pageref{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74})} 

{\bf final}{\rm (p.\,\pageref{classost_1_1_thread_6fb521eb3d23c51925472a3fe0abf327})} \end{Desc}


Reimplemented in {\bf ost::TCPSession} {\rm (p.\,\pageref{classost_1_1_t_c_p_session_d0a0568018d48cc3079222156a6af093})}, and {\bf ost::Unix\-Session} {\rm (p.\,\pageref{classost_1_1_unix_session_5762091d1418fca6b4970c9c5a5b347f})}.\index{ost::Thread@{ost::Thread}!isDetached@{isDetached}}
\index{isDetached@{isDetached}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool ost::Thread::is\-Detached (void)}\label{classost_1_1_thread_fab1a3194f6c0753748584a6c68e8e28}


Check if this thread is detached. 

\begin{Desc}
\item[Returns:]true if the thread is detached. \end{Desc}
\index{ost::Thread@{ost::Thread}!isRunning@{isRunning}}
\index{isRunning@{isRunning}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool ost::Thread::is\-Running (void)}\label{classost_1_1_thread_16f6de1f41e82c6edee5465922dfe5ab}


Verifies if the thread is still running or has already been terminated but not yet deleted. 

\begin{Desc}
\item[Returns:]true if the thread is still executing. \end{Desc}
\index{ost::Thread@{ost::Thread}!isThread@{isThread}}
\index{isThread@{isThread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool ost::Thread::is\-Thread (void)}\label{classost_1_1_thread_c25f1fcbb5f0cb2e683d746c94b255f6}


Tests to see if the current execution context is the same as the specified thread object. 

\begin{Desc}
\item[Returns:]true if the current context is this object. \end{Desc}
\index{ost::Thread@{ost::Thread}!join@{join}}
\index{join@{join}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::join (void)}\label{classost_1_1_thread_1e6d355ea0d9b0b023f3fc2aa91a25e8}


Blocking call which unlocks when thread terminates. 

\index{ost::Thread@{ost::Thread}!notify@{notify}}
\index{notify@{notify}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual void ost::Thread::notify ({\bf Thread} $\ast$)\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classost_1_1_thread_390827ad98d3402dd84ee9f128bcd564}


When a thread terminates, it now sends a notification message to the parent thread which created it. 

The actual use of this notification is left to be defined in a derived class.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em -}]the thread that has terminated. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!resume@{resume}}
\index{resume@{resume}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::resume (void)}\label{classost_1_1_thread_0861f734ad77b1ba517fce302215e41e}


Resumes execution of the selected thread. 

\index{ost::Thread@{ost::Thread}!run@{run}}
\index{run@{run}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual void ost::Thread::run (void)\hspace{0.3cm}{\tt  [protected, pure virtual]}}\label{classost_1_1_thread_dd7d339d94b8a1ed2b2b0324a95b7e74}


All threads execute by deriving the Run method of {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})}. 

This method is called after Initial to begin normal operation of the thread. If the method terminates, then the thread will also terminate after notifying it's parent and calling it's Final() method.

\begin{Desc}
\item[See also:]Initial \end{Desc}
\begin{Desc}
\item[Examples: ]\par
{\bf bug1.cpp}, {\bf bug2.cpp}, {\bf tcpservice.cpp}, {\bf tcpstr1.cpp}, {\bf tcpthread.cpp}, {\bf thread1.cpp}, and {\bf thread2.cpp}.\end{Desc}
\index{ost::Thread@{ost::Thread}!setCancel@{setCancel}}
\index{setCancel@{setCancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::set\-Cancel ({\bf Cancel} {\em mode})\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_4bff373a83b90f6f44d1519ef893e35b}


Sets thread cancellation mode. 

Threads can either be set immune to termination (cancel\-Disabled), can be set to terminate when reaching specific \char`\"{}thread cancellation points\char`\"{} (cancel\-Deferred) or immediately when Terminate is requested (cancel\-Immediate).

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mode}]for cancellation of the current thread. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!setException@{setException}}
\index{setException@{setException}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static void ost::Thread::set\-Exception ({\bf Throw} {\em mode})\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_e9f30b27ca1322ccc3325ba9ca5157fa}


Set exception mode of the current thread. 

\begin{Desc}
\item[Returns:]exception mode. \end{Desc}
\index{ost::Thread@{ost::Thread}!setName@{setName}}
\index{setName@{setName}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::set\-Name (const char $\ast$ {\em text})\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_b6f72653183c4db0dfd6b254ddbf072e}


Set the name of the current thread. 

If the name is passed as NULL, then the default name is set (usually object pointer).

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em text}]name to use. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!setStack@{setStack}}
\index{setStack@{setStack}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static void ost::Thread::set\-Stack (size\_\-t {\em size} = {\tt 0})\hspace{0.3cm}{\tt  [inline, static]}}\label{classost_1_1_thread_ccd29b724539d63a8495d954f9f56c72}


Set base stack limit before manual stack sizes have effect. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em size}]stack size to set, or use 0 to clear autostack. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!setSuspend@{setSuspend}}
\index{setSuspend@{setSuspend}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::set\-Suspend ({\bf Suspend} {\em mode})\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_d226f8bca85bf68ce71d90baca6434d6}


Sets the thread's ability to be suspended from execution. 

The thread may either have suspend enabled (suspend\-Enable) or disabled (suspend\-Disable).

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mode}]for suspend. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!sleep@{sleep}}
\index{sleep@{sleep}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static void ost::Thread::sleep ({\bf timeout\_\-t} {\em msec})\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_663d960e8599194f3b25169915c22fb6}


A thread-safe sleep call. 

On most Posix systems, \char`\"{}sleep()\char`\"{} is implimented with SIGALRM making it unusable from multipe threads. Pthread libraries often define an alternate \char`\"{}sleep\char`\"{} handler such as usleep(), nanosleep(), or nap(), that is thread safe, and also offers a higher timer resolution.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em msec}]timeout in milliseconds. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!start@{start}}
\index{start@{start}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int ost::Thread::start ({\bf Semaphore} $\ast$ {\em start} = {\tt 0})}\label{classost_1_1_thread_2ef198d7aefb93cf9de4fcc6b66c27a2}


When a new thread is created, it does not begin immediate execution. 

This is because the derived class virtual tables are not properly loaded at the time the C++ object is created within the constructor itself, at least in some compiler/system combinations. The thread can either be told to wait for an external semaphore, or it can be started directly after the constructor completes by calling the {\bf start()}{\rm (p.\,\pageref{classost_1_1_thread_2ef198d7aefb93cf9de4fcc6b66c27a2})} method.

\begin{Desc}
\item[Returns:]error code if execution fails. \end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em start}]optional starting semaphore to alternately use. \end{description}
\end{Desc}
\begin{Desc}
\item[Examples: ]\par
{\bf tcpservice.cpp}, and {\bf tcpstr1.cpp}.\end{Desc}
\index{ost::Thread@{ost::Thread}!suspend@{suspend}}
\index{suspend@{suspend}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::suspend (void)}\label{classost_1_1_thread_5f1b650c1f3b71e458adfbd86b3acb83}


Suspends execution of the selected thread. 

Pthreads do not normally support suspendable threads, so the behavior is simulated with signals. On systems such as Linux that define threads as processes, SIGSTOP and SIGCONT may be used. \index{ost::Thread@{ost::Thread}!sync@{sync}}
\index{sync@{sync}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::sync (void)\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_1cda4748073c4d55e2d0504e7c9b09cc}


Used to wait for a join or cancel, in place of explicit exit. 

\index{ost::Thread@{ost::Thread}!terminate@{terminate}}
\index{terminate@{terminate}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ost::Thread::terminate (void)\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_e71c94c24733ed82f9b74c034744d002}


Used by another thread to terminate the current thread. 

Termination actually occurs based on the current {\bf set\-Cancel()}{\rm (p.\,\pageref{classost_1_1_thread_4bff373a83b90f6f44d1519ef893e35b})} mode. When the current thread does terminate, control is returned to the requesting thread. {\bf terminate()}{\rm (p.\,\pageref{classost_1_1_thread_e71c94c24733ed82f9b74c034744d002})} should always be called at the start of any destructor of a class derived from {\bf Thread}{\rm (p.\,\pageref{classost_1_1_thread})} to assure the remaining part of the destructor is called without the thread still executing. \index{ost::Thread@{ost::Thread}!testCancel@{testCancel}}
\index{testCancel@{testCancel}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool ost::Thread::test\-Cancel (void)\hspace{0.3cm}{\tt  [protected]}}\label{classost_1_1_thread_f8afe7a3330b69dff685415aae14657c}


test a cancellation point for deferred thread cancellation. 

\index{ost::Thread@{ost::Thread}!yield@{yield}}
\index{yield@{yield}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static void ost::Thread::yield (void)\hspace{0.3cm}{\tt  [static]}}\label{classost_1_1_thread_3f4a4f9872ed8f80a591e6b020ecf5d7}


Yields the current thread's CPU time slice to allow another thread to begin immediate execution. 



\subsection{Friends And Related Function Documentation}
\index{ost::Thread@{ost::Thread}!Cancellation@{Cancellation}}
\index{Cancellation@{Cancellation}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}friend class {\bf Cancellation}\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_bbf97e2c58c760acb67b9db3a7ba11db}


\index{ost::Thread@{ost::Thread}!DummyThread@{DummyThread}}
\index{DummyThread@{DummyThread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}friend class Dummy\-Thread\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_9b6e94561c96e07e8f2dd776bbc19396}


\index{ost::Thread@{ost::Thread}!operator++@{operator++}}
\index{operator++@{operator++}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void operator++ ({\bf Thread} \& {\em th})\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_2742c471d2abe8712368ccff8d534702}


Signal the semaphore that the specified thread is waiting for before beginning execution. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em th}]specified thread. \end{description}
\end{Desc}
\index{ost::Thread@{ost::Thread}!operator--@{operator--}}
\index{operator--@{operator--}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void operator-- ({\bf Thread} \& {\em th})\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_a797f8e5a1ea5b857251f98f0d50614e}


\index{ost::Thread@{ost::Thread}!PosixThread@{PosixThread}}
\index{PosixThread@{PosixThread}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}friend class {\bf Posix\-Thread}\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_bc1a729c4204bc85f58c47042f429acb}


\index{ost::Thread@{ost::Thread}!postream_type@{postream\_\-type}}
\index{postream_type@{postream\_\-type}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}friend class postream\_\-type\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_e156bb5074cfe5c3a729890e0ded952f}


\index{ost::Thread@{ost::Thread}!Slog@{Slog}}
\index{Slog@{Slog}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}friend class {\bf Slog}\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_f08013a89bf19b835ba6f75a60f870ed}


\index{ost::Thread@{ost::Thread}!ThreadImpl@{ThreadImpl}}
\index{ThreadImpl@{ThreadImpl}!ost::Thread@{ost::Thread}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}friend class Thread\-Impl\hspace{0.3cm}{\tt  [friend]}}\label{classost_1_1_thread_e3c1cdb20d70b22a5c0bf395614eefff}




Reimplemented in {\bf ost::Posix\-Thread} {\rm (p.\,\pageref{classost_1_1_posix_thread_e3c1cdb20d70b22a5c0bf395614eefff})}.

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