Clipper
|
Thread base class: Override this to create new threads. More...
#include <clipper_thread.h>
Public Member Functions | |
bool | run () |
bool | join () |
int | id () const |
Static Public Member Functions | |
static void | lock () |
static void | unlock () |
Protected Member Functions | |
virtual void | Run ()=0 |
Thread base class: Override this to create new threads.
To create a thread, override this class. Store data as members with accessors to set input and read output. Override the Run() method to do the actual work. e.g. the following class implements a thread which can sum a list of numbers.
class Thread_test : public Thread_base { public: class Data : public std::vector<int> { public: Data() {} Data( std::vector<int> v ) : std::vector<int>(v) {} }; void Run() { sum = 0; while ( 1 ) { lock(); int c = current++; unlock(); if ( c >= data_.size() ) break; sum += data_[c]; } } static void set_data( Data d ) { data_ = d; } static Data data_; static int current; int sum; };