Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2004-07-31 04:48:58


Aaron W. LaFramboise wrote:
> Following is an implementation of, and some comments on, a staticly
> linked Boost.Thread thread exit handler for MSVC.

Wow, great. It works on MSVC71, but not on MSVC6. I tried following,
very simple test code, compiled with any of CRT variants /MD /MDd /MT or
/MTd . What's meaning of data_seg(".CRT$XLB")?

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

DWORD WINAPI f(void *)
{
        Sleep(500);
        return 0;
}

// Report thread and process detach events.
void NTAPI tls_callback(PVOID, DWORD Reason, PVOID)
{
        if(Reason == DLL_THREAD_DETACH)
                Beep(440, 100);
        else if(Reason == DLL_PROCESS_DETACH)
                Beep(880, 50);
}

int main(int argc, char* argv[])
{
        DWORD id;
        HANDLE h = CreateThread(NULL, 0, &f, 0, 0, &id);
        WaitForSingleObject(h, INFINITE);
        CloseHandle(h);
        
        Sleep(300);
        
        return 0;
}

#pragma optimize ("", off)
namespace
{
   // "__declspec(thread)" is documented in MSDN to create .tls section
        extern __declspec(thread) int dummy_ = 1;
        int dummy() {return dummy_;}
}
#pragma optimize ("", on)

#pragma data_seg(".CRT$XLB")
DWORD callback_ptr = (DWORD)tls_callback;


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