Hi,
My class contains a member var that is a little buffer used as a cache.
Instances of this class are used concurrently (referenced through a
shared_ptr).
I would like to switch my buffer to a thread_specific_ptr, but there are
two big problems with using thread_specific_ptr as a member var:
1. There is a memory leak when my object goes away, because by design only
one of the pointers gets cleaned up (the one for the thread that happens to
delete the object).
2. There is undefined behavior when a new object gets created that happens
to be allocated at the same address as a previously freed one. get( )
could return a pointer to a buffer that goes with an old (now freed) object.
I try not to question the wisdom of the thread_specific_ptr authors, but
given these two issues, especially #2, I have to conclude that
thread_specific_ptr is only suitable for statics / globals. It is wholly
unfit to be used as a member variable (except in a singleton class I guess).
The next best thing I can think of for my class is to just have a
std::map