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")?

#include <windows.h>

DWORD WINAPI f(void *)
        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);
        return 0;

#pragma optimize ("", off)
   // "__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, gregod at, cpdaniel at, john at