Boost logo

Boost :

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


On 09/05/2010 21:53, Neil Groves wrote:
> On Sat, May 8, 2010 at 7:56 PM, Tanguy Fautré<tfautre_at_[hidden]> wrote:
>>
>> Is thread_specific_ptr supposed to work even when initialized by another
>> static object? Or does it require to be initialized only after entering
>> main?
>>
>>
> I don't believe there are any inter-compilation unit dependencies hence it
> should work if your initialization order is compliant with the usual C++
> standard guarantees.

That was my understanding too.

> The supplied C++ example does not reproduce the problem for me with the
> boost trunk or the boost release branch in debug or release configurations
> using the default compilation options on VC 10 Express. I have checked for
> changes between the release branch and the 1.43 release and nothing relevant
> appears to have changed.
>
> Would you please provide more details about how to reproduce the problem?

Find all the details below.

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.

I've got everything compiled in x64 on Win7. I'll give it a try tomorrow
at the office with Boost in x86.

Regards,

Tanguy

1/ Compiled Boost 1.43.0 by running the following bat script in "Visual
Studio x64 Win64 Command Prompt (2010)" (the ZLIB defines are probably
irrelevant in this case, but I copy/pasted the whole thing just in case).

bjam.exe -j2 --toolset=msvc --build-type=complete address-model=64
define=_CRT_SECURE_NO_WARNINGS=0 define=_SCL_SECURE_NO_WARNINGS=0
define=ZLIB_INCLUDE=C:\Development\libraries\platform\win64\vc100\include define=ZLIB_LIBPATH=C:\Development\libraries\platform\win64\vc100\lib
runtime-link=shared link=shared debug install

bjam.exe -j2 --toolset=msvc --build-type=complete address-model=64
define=_CRT_SECURE_NO_WARNINGS=0 define=_SCL_SECURE_NO_WARNINGS=0
define=ZLIB_INCLUDE=C:\Development\libraries\platform\win64\vc100\include define=ZLIB_LIBPATH=C:\Development\libraries\platform\win64\vc100\lib
runtime-link=shared link=static debug install

bjam.exe -j2 --toolset=msvc --build-type=complete address-model=64
define=_CRT_SECURE_NO_WARNINGS=0 define=_SCL_SECURE_NO_WARNINGS=0
define=ZLIB_INCLUDE=C:\Development\libraries\platform\win64\vc100\include define=ZLIB_LIBPATH=C:\Development\libraries\platform\win64\vc100\lib
runtime-link=shared link=shared release install

bjam.exe -j2 --toolset=msvc --build-type=complete address-model=64
define=_CRT_SECURE_NO_WARNINGS=0 define=_SCL_SECURE_NO_WARNINGS=0
define=ZLIB_INCLUDE=C:\Development\libraries\platform\win64\vc100\include define=ZLIB_LIBPATH=C:\Development\libraries\platform\win64\vc100\lib
runtime-link=shared link=static release install

2/ Compiled the given example program using CMake 2.8.1 with VC10 x64.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(TssTest)

IF (WIN32)

        ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
        ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
        ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
        ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
        ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
        
        SET(Boost_USE_STATIC_LIBS ON)
        
ENDIF (WIN32)

FIND_PACKAGE(Boost REQUIRED COMPONENTS thread)

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

ADD_EXECUTABLE(main tss_static_order.cpp)
TARGET_LINK_LIBRARIES(main ${Boost_THREAD_LIBRARY})

3/ Ran the program in Debug mode. It fails by printing "ERROR: verifyTss
failed (nullptr)".


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