Boost logo

Boost Users :

From: anthony kelly (pinkeye888_at_[hidden])
Date: 2008-01-26 18:54:27


Hello Boost Users,

I would like to implement a simple threaded class like this:

class C
{
  public:
    void Start();
    void Stop();

  private:
    bool running;
    boost::thread t;
    void ThreadJob();
}

void C::Start()
{
    running = true;
    t = boost::thread(&C::ThreadJob);
}

void C::Stop()
{
    running = false;
    t.join();
}

void C::ThreadJob()
{
    while(running);
}

However, the syntax for this line is wrong:
    t = boost::thread(&C::ThreadJob);

The only examples I can find show starting the thread at the same time it is
defined! Is it possible to define the thread as a class member, and start it
later? If so, what would the syntax for this line be? If not, can you
suggest an alternative structure?

Thank you,

Anthony



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net