Boost logo

Boost :

Subject: Re: [boost] [thread] thread_specific_ptr and static initialization order
From: Tanguy Fautré (tfautre_at_[hidden])
Date: 2010-05-09 19:13:54


On 09/05/2010 23:36, Tanguy Fautré wrote:
>
> Note that the problem only appears in debug mode. It seems that in the
> last call to verifyTss(), TlsGetValue()
> (boost_1_43_0\libs\thread\src\win32\thread.cpp, line 53) returns NULL
> (with GetLastError() == 0) instead of the expected thread data.

Found the problem!
It is indeed a static initialization order.

The problem is that create_current_thread_tls_key() is called twice,
even though it should be protected by call_once (line 58), leading to
two TLS instead of one.

boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);

is being called (from init_tss static constructor) before
"current_thread_tls_init_flag" is properly initialized with
BOOST_ONCE_INIT (line 28).

Note that boost::once_flag is a struct type with a destructor and no
constructor. BOOST_ONCE_INIT is a define to {0,0,0,0}. Effectively
leading to:

boost::once_flag current_thread_tls_init_flag={0,0,0,0};

I've got no idea what the standard says about such a case with respect
to the static initialization order problem.

Tanguy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk