OpenDaVINCI  4.15.3
odcore::wrapper::Thread Class Referenceabstract

#include <Thread.h>

Inheritance diagram for odcore::wrapper::Thread:
Inheritance graph

Public Member Functions

virtual ~Thread ()
 
virtual bool start ()=0
 
virtual bool stop ()=0
 
virtual bool isRunning () const =0
 

Detailed Description

This class controls a thread. It can be used to start different types of Runnables.

It can be used as follows:

class MyRunnable : public Runnable {
public:
bool running;
virtual bool isRunning() {
// Implement some logic for controlling the running state.
return running;
}
virtual void run() {
// Do some things right here.
}
};
...
MyRunnable r;
r.running = false;
unique_ptr<Thread> t;
try {
t = unique_ptr<Thread>(ConcurrencyFactory::createThread(r));
}
catch(string &s) {
clog << "Failed: " << s << endl;
}
if (t.get() != NULL) {
r.running = true;
t->start();
}
...
// Do some different things.
...
if (t.get() != NULL) {
r.running = false;
t->stop();
}

Constructor & Destructor Documentation

odcore::wrapper::Thread::~Thread ( )
virtual

Member Function Documentation

virtual bool odcore::wrapper::Thread::isRunning ( ) const
pure virtual

This method returns true, iff the thread is running.

Returns
true, iff the thread is running.

Implemented in odcore::wrapper::WIN32Impl::WIN32Thread, and odcore::wrapper::POSIX::POSIXThread.

virtual bool odcore::wrapper::Thread::start ( )
pure virtual

This method starts a thread.

Returns
true, iff the thread could be started.

Implemented in odcore::wrapper::WIN32Impl::WIN32Thread, and odcore::wrapper::POSIX::POSIXThread.

virtual bool odcore::wrapper::Thread::stop ( )
pure virtual

This method stops a thread. A stopped thread cannot be restarted.

Returns
true, iff the thread could be stopped.

Implemented in odcore::wrapper::WIN32Impl::WIN32Thread, and odcore::wrapper::POSIX::POSIXThread.