class ThreadIf

A wrapper class to create and spawn a thread

Public Methods

virtual void exit()
forces the thread running to exit()
bool isShutdown()
returns true if the thread has been asked to shutdown_ or if the thread is not running
virtual void join()
joins to the thread running thread()
virtual void run()
runs the code in thread() . Returns immediately
void shutdown()
request the thread running thread() to return, by setting the bool shutdown_
virtual void thread()
thread is a virtual method
ThreadIf()
default constructor
virtual ~ThreadIf()
destructor

Protected Fields

VThread itsThread
itsThread is protected so that thread() can retrieve its threadId

Private Methods

const ThreadIf& operator=(const ThreadIf &)
Suppress copying
ThreadIf(const ThreadIf &)
Suppress copying

Documentation

A wrapper class to create and spawn a thread. It is a base class. ThreadIf::thread() is a pure virtual method .

Usage: To use this class, derive from it and override the thread() method. To start the thread, call the run() method. The code in thread() will run in a separate thread.

Call shutdown() from the constructing thread to shut down the code. This will set the bool shutdown_ to true. The code in thread() should react properly to shutdown_ being set, by returning. Call join() to join the code.

Sample:

...
DerivedThreadIf thread;
thread.run();
... do stuff ...
thread.shutdown();
thread.join();
ThreadIf()
default constructor

virtual ~ThreadIf()
destructor

virtual void run()
runs the code in thread() . Returns immediately

virtual void join()
joins to the thread running thread()

virtual void exit()
forces the thread running to exit()

void shutdown()
request the thread running thread() to return, by setting the bool shutdown_

bool isShutdown()
returns true if the thread has been asked to shutdown_ or if the thread is not running

virtual void thread()
thread is a virtual method. Users should derive and define thread() such that it returns when isShutdown() is true.

VThread itsThread
itsThread is protected so that thread() can retrieve its threadId

ThreadIf(const ThreadIf &)
Suppress copying

const ThreadIf& operator=(const ThreadIf &)
Suppress copying


This class has no child classes.

alphabetic index hierarchy of classes


generated by doc++