C++11 have introduced a new "thread_local" keyword for per-thread data storage. My impression is that compiler support for the keyword is not yet widely available. However, most compilers have already supported non-standard variants of the keyword for the past decade. GCC has e.g. supported "__thread" since GCC 3.3.1 (2003), and MSVC has supported "__declspec(thread)" since 2003.

It would be great if Boost could introduce some form of "BOOST_THREAD_LOCAL" macro for portable "thread_local" support also for non-C++11 compilers. From the boost::thread documentation, I can see that there already is a thread_specific_ptr class available, but that seems more like a per-thread smart-pointer than a general mechanism for thread-local storage.

Any comments?

Example draft implementation:
#ifndef BOOST_THREAD_LOCAL
#  if __cplusplus >= 201103L
#    define BOOST_THREAD_LOCAL thread_local
#  elif defined _MSC_VER
#    define BOOST_THREAD_LOCAL __declspec(thread)
#  else
#    define BOOST_THREAD_LOCAL __thread
#  endif
#endif

Regards,
Fredrik