1

I use the thread local storage with boost. I have a global variable :

boost::thread_specific_ptr<MyDataClass> p_timeline_ctx;

and I have the following class, which encapsulates a boost::thread object and contains an additionnal data object :

class MyThread {
   private :
      boost::thread t;
      MyDataClass d;

   public :
      MyThread():c() {}

      void start(void) {
         ptr.reset(this->d);
         this->t = boost::thread(&MyThread::worker, this);
      }

      void worker(void) {
         // do something
      }

};

I do not get any error when compiling. But on runtime, when the worker function exits and the thread ends, I get a "glibc ... free ... invalid pointer" error.

I guess this comes from the fact that, according to the boost doc, the thread_specific_ptr tries to delete the object it points to when threads end. But I do not see how to solve the problem.

4

1 に答える 1