Boost logo

Boost :

Subject: [boost] [thread][thread_specific_ptr]
From: Sid Sacek (ssacek_at_[hidden])
Date: 2009-10-27 21:40:12

In VC++ and GCC a user creates global TLS like this:

      __declspec( thread ) int tls_1;

      __thread int tls_2;

But using the boost library

      boost::thread_specific_ptr< int > tls_3;

doesn't provide an initialized global variable as one would expect from thread-local-storage. Using tls_3 crashes the program if it's not pre-initialized to some object. The implication is that every time a new thread is created, it needs to first instantiate all global TLS objects.

Am I not understanding the intentions of this class? Is there a proper or intended way of using this class? I couldn't find any example code in the boost archives.


Boost list run by bdawes at, gregod at, cpdaniel at, john at