Changeset 2212 in Sophya for trunk/SophyaLib/SysTools/zthread.cc


Ignore:
Timestamp:
Oct 15, 2002, 5:48:53 PM (23 years ago)
Author:
ansari
Message:

Mise a jour de la documentation SysTools, Reza 15/10/2002

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/zthread.cc

    r1612 r2212  
    55#include <stdlib.h>
    66#include <stdio.h>
     7
     8/*!
     9  \class SOPHYA::ZThread
     10  \ingroup SysTools
     11  This class provides an interface for creating and controlling threads.
     12  The implementation uses the POSIX thread interface.
     13  The ZThread objects can be sub classed with the redefinition of
     14  the \c run() method which then performs the task.
     15  The default \c run() method of the base class can be used directly
     16  to perform computation through a function (see \b setAction() method)
     17  \sa SOPHYA::ZMutex
     18  The following sample code shows the usage of ZThread object
     19  to run simultaneously to functions to perform computation.
     20
     21  \code
     22  // The functions to perform computing
     23  void fun1(void *arg) { }
     24  void fun2(void *arg) { }
     25  // ...
     26  ZThread zt1;
     27  zt1.setAction(fun1, arg[1]);
     28  ZThread zt2;
     29  zt2.setAction(fun2, arg[1]);
     30  cout << " Starting threads ... " << endl;
     31  zt1.start();
     32  zt2.start();
     33  cout << " Waiting for threads to end ... " << endl; 
     34  zt1.join();
     35  zt2.join();
     36  \endcode
     37*/
    738
    839#define CheckSt(st_, strg_)  if (st_ != 0)  perror(strg_);
     
    2455
    2556/* ------ Classe ZThread  -------  */
    26 
     57/*!
     58  Constructor, with optional specification of the thread stack size.
     59*/
    2760ZThread::ZThread(size_t stacksize)
    2861{
     
    3972}
    4073
     74/*!
     75  Method which starts the thread.
     76*/
    4177void ZThread::start()
    4278{
     
    5490}
    5591
    56 
     92/*!
     93  Calls the pthread_cancel. Can be used to stop a running thread.
     94*/
    5795void ZThread::cancel()
    5896{
     
    64102
    65103
     104/*!
     105  Waits for the thread to terminate.
     106*/
    66107void ZThread::join()
    67108{
     
    73114}
    74115
     116/*!
     117  This virtual method can be redefined in the derived class, in order
     118  to perform the actual computation.
     119*/
    75120void ZThread::run()
    76121{
     
    82127
    83128/* ------ Classe ZMutex -------  */
     129/*!
     130  \class SOPHYA::ZMutex
     131  \ingroup SysTools
     132  This class implements an interface to the Mutual Exclusion objects
     133  of the POSIX threads.
     134  The ZMutex objects should be used to control acces from different threads
     135  to common objects through the \b lock() and \b unlock() methods. 
     136  \sa SOPHYA::ZSync
     137*/
    84138
     139/*!
     140  Constructor: Creates a associated pair of POSIX \c pthread_mutex_t
     141  and \c pthread_cond_t objects
     142*/
    85143ZMutex::ZMutex()
    86144{
     
    100158}
    101159
     160/*!
     161  \class SOPHYA::ZSync
     162  \ingroup SysTools
     163  This class can be used to insure that the execution of a given
     164  part of the code is synchronised, i.e. only a single thread
     165  goes through this at a given time.
     166  The constructor acquires a lock on given \b ZMutex object,
     167  which is released by the destructor.
     168  The ZSync object should then be instanciated at the beginning of
     169  the synchronised instruction bloc.
     170  \sa SOPHYA::ZMutex
     171*/
Note: See TracChangeset for help on using the changeset viewer.