Eric Rosenquist wrote:

The per-thread map never seems to get
deleted anywhere when the thread terminates.



I had a closer look to threadspecificdata.cpp. It seems that no mecanism is provided to allow an automatic deletion of objects on thread termination. Adding it would be a more clean and reliable solution to this memory leak.
This can easily be done, at least with pthreads, with a templated class looking like :


template<class T>
class TSD
{
   public:
      TSD(): key(0) {
           pthread_key_create(&key, &destr_function);
      }

      // ...

   private:
       static void destr_function(void * data) {
            delete static_cast<T*>(data);
       }
       pthread_key_t key;
};


If it's possible to do it with msthreads (I guess so) I'd like to propose a more complete TSD handling solution.
If we do it, we can profit of the occasion to use the pimpl idiom on ThreadSpecificData, which would solve the HAVE_PTHREAD macro problem, at least for this file.


Any idea/suggestion welcome,


Christophe



Reply via email to