12 Haziran 2017 Pazartesi

thread thread_specific_ptr Sınıfı

Giriş
Açıklaması şöyle. C++11'deki thread_local değişken gibidir. Pointer'lar ile çalışır.
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.
Açıklaması şöyle
The thread-local pointers are platform dependent, but the object you store via it is just on the heap.
Açıklaması şöyle
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.
Bu sınıf kopyalanamaz.
Constructor
Şöyle yaparız.
boost::thread_specific_ptr <Foo> ptr;
get metodu
Şöyle yaparız.
Foo* f =  ptr.get();

Hiç yorum yok:

Yorum Gönder