Tamás Szelei
Tamás Szelei

Reputation: 23971

On which platforms does thread_specific_pointer work without boost::thread?

The documentation of boost::thread_specific_ptr states (emphasis mine):

Note: on some platforms, cleanup of thread-specific data is not performed for threads created with the platform's native API. On those platforms such cleanup is only done for threads that are started with boost::thread unless boost::on_thread_exit() is called manually from that thread.

What are these platforms where cleanup is not performed? (motivation: I would like to emulate thread_local with a pre-C++11 compiler and calling the destructor of the pointed-to objects is crucial).

Upvotes: 0

Views: 162

Answers (1)

Andrey Semashev
Andrey Semashev

Reputation: 10614

POSIX threads (pthreads) provide interface for cleaning up thread-local storage, so this remark does not refer to any platforms correctly supporting pthreads.

On Windows there is no native API for TLS cleanup, so the library has to resort to various hacks to implement this. From the source (see here for the case when Boost.Thread is built as a dll, and here for when it is a static library) you can see that MSVC and MinGW/MinGW-w64 are supported. The dll version is fairly portable, so the cleanup implementation may be missing if you use some exotic compiler on Windows and Boost.Thread is built as a static library.

Boost.Thread provides an indication mechanism for the case when user is required to provide TLS cleanup implementation. The application won't link because of a missing function boost::tss_cleanup_implemented. When such error appears, the user is expected to implement the TLS cleanup and this function (and empty implementation will suffice). When the cleanup is implemented by Boost.Thread, that function is defined by Boost.Thread as well.

Upvotes: 2

Related Questions