$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Chameleon (gessos.paul_at_[hidden])
Date: 2008-01-07 07:16:03
I have a strange problem with the code below.
>From outside the function operator()(), I can have the pointer to 
thread object 'thread'.
>From inside operator()() 'thread' is always 0.
Why does this happen?
------------------------------------------------------------------
#include <cstdio>
#include <boost/thread/thread.hpp>
class A
{
    boost::thread *thread;
public:
    A() : thread(0) {}
    ~A() { join(); }
    void createThread() { thread = new boost::thread(*this); }
    void operator()() {
        printf("Starting thread with pointer: %d\n", thread);           //<<<<<<<<<<<<<<HERE!
        delete thread; thread = 0;
    }
    void join() { if (thread) thread->join(); }
};
int main(int, char**) {
    A a;
    a.createThread();
    a.join();
    return 0;
}
------------------------------------------------------------------