Clipper
Public Member Functions | Static Public Member Functions | Protected Member Functions
clipper::Thread_base Class Reference

Thread base class: Override this to create new threads. More...

#include <clipper_thread.h>

List of all members.

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

Detailed Description

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;
};

The documentation for this class was generated from the following files: