Opened 11 years ago

Closed 11 years ago

#5837 closed Bugs (invalid)

tss_dll: does not appear to allocate TLS storage at the proper time

Reported by: noloader@… Owned by: Anthony Williams
Milestone: To Be Determined Component: thread
Version: Boost 1.47.0 Severity: Problem
Keywords: tss Cc: noloader@…

Description

When a Windows process loads a DLL, DllMain will recieve DLL_PROCESS_ATTACH. According to MSDN process can use the opportunity to allocate thread storage [1]. Interestingly, on_process_enter() (and on_thread_enter()) does not perform the initialization. Note that on_process_enter() is the Boost routine for DLL_PROCESS_ATTACH; and on_thread_enter() is called for DLL_THREAD_ATTACH.

From tss_hooks.cpp:

extern "C" BOOST_THREAD_DECL void on_process_enter()
{
}

and

extern "C" BOOST_THREAD_DECL void on_thread_enter()
{
}

Even more bizarre, on_thread_exit() appears to allocate the thread local storage:

extern "C" BOOST_THREAD_DECL void on_thread_exit()
{
    // Initializing tls_key here ensures its proper visibility
    boost::call_once( init_tls_key, once_init_tls_key );

    // Get the exit handlers list for the current thread from tls.
    if( tls_key == invalid_tls_key )
    {
        return;
    }
    ...

Perhaps it would be a good idea to review the MSDN documentation, and perfom TLS initialization according to Microsoft recommendations.

[1] http://msdn.microsoft.com/en-us/library/ms682583(v=vs.85).aspx

Change History (3)

comment:1 by Jeffrey Walton <noloader@…>, 11 years ago

Cc: noloader@… added
Component: Nonethread
Owner: set to Anthony Williams

comment:2 by viboes, 11 years ago

Keywords: tss added

comment:3 by viboes, 11 years ago

Resolution: invalid
Status: newclosed

Closed as the file tss_hooks.cpp doesn't exists

The current code is

    BOOST_THREAD_DECL void __cdecl on_process_enter()
    {}

    BOOST_THREAD_DECL void __cdecl on_thread_enter()
    {}

    BOOST_THREAD_DECL void __cdecl on_process_exit()
    {
        boost::cleanup_tls_key();
    }

    BOOST_THREAD_DECL void __cdecl on_thread_exit()
    {
        boost::run_thread_exit_callbacks();
    }
Note: See TracTickets for help on using tickets.