Back to thread library pages
Currently, when you set thread-specific storage with:
thread_specific_ptr<mystruct> val; ... val.reset(ptr);
then, when the thread dies, delete is automatically invoked on ptr. This can be problematical.
It would be nice if there were a version of thread_specific_ptr which didn't delete on exit. It would be natural to implement this with a trait, e.g.:
thread_specific_ptr<mystruct, non_deleting> val;
- People/Chuck Messenger
Could it be solved using a secondary template argument to reset, as shared_ptr?
thread_specific_ptr<mystruct> val; val.reset(new int, some_argument_here)
- People/Anders Dalvander
Why Do you think it is problematic? After the thread has gone noone can get access to the pointer anyhow. This is what TLS is for.
Of course this is not true if you try to access the pointer also from a second thread. Avoid this, as this is misusing the concept of TLS.