The C++11 standard contains a new addition - the thread_local specifier - which makes static variables thread-local. The standard thread_local supports non-trivial types - t
no.
gcc does currently not have the ability to run ctor/dtor for __thread stuff on thread creation/destruction, so unless you dont need ctor/dtor to run (in which case __thread is exactly what you need, and nothing to emulate on top of it is needed), there is nothing yet that works like thread_local.
If however you can live with lazy initialization (like__thread T* ptr; if(!ptr){...}
) you can hack something together with pthread_key_create
where you can register a destruction function that will be run at thread destruction, and then you can register all your pointers there.
Or you can use boost::thread_specific_ptr
which more or less does this (possibly without using the __thread TLS as underlying implementation detail)