$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Markus Werle (numerical.simulation_at_[hidden])
Date: 2007-08-01 10:26:21
Hi!
After some nightmare chasing a bug within my code
I boiled it down to a dummy MFC MDI project including nothing
else but <boost/thread/tss.hpp>
the line 
static boost::thread_specific_ptr<void *> tld_helper;
in InitInstance()
triggers an "R6030 - CRT not initialized" error, but only on
one single windows XP platform. The app runs fine on all others.
If you have any idea what might have gone wrong, please give me a hint.
I put some simplified code below. Excluding the init() line in 
boost::details::tss(boost::function1<void, void*>* pcleanup)
removes the initializing error in the executable :-(
best regards, 
Markus
My compiler settings:
Microsoft Visual Studio 2005
Version 8.0.50727.762  (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
[...]
Microsoft Visual C++ 2005   77626-009-0000007-41492
Microsoft Visual C++ 2005
Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)
Compiler flags:
/Ox /Ob2 /Oi /Ot /I "D:\FEV-Data\Sourcen\cpp\VC8\Common\DLLs\boost_1_34_0" /D
"WIN32" /D "_WINDOWS" /D "NDEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /D "_MBCS" /FD
/EHsc /MT /Yu"stdafx.h" /Fp"Release\MaximumCM_Dummy.pch" /Fo"Release\\"
/Fd"Release\vc80.pdb" /W3 /nologo /c /TP /errorReport:prompt /bigobj /wd4996
Linker flags
/OUT:"D:\FEV-Data\ExperimentalCode\WerleShowBug\Release\MaximumCM_Dummy.exe"
/INCREMENTAL:NO /NOLOGO
/LIBPATH:"d:\FEV-Data\Sourcen\cpp\VC8\Common\DLLs\boost_1_34_0\stage\lib"
/MANIFEST /MANIFESTFILE:"Release\MaximumCM_Dummy.exe.intermediate.manifest"
/DELAYLOAD:"OleAcc.dll" /DEBUG
/PDB:"d:\FEV-Data\ExperimentalCode\WerleShowBug\release\MaximumCM_Dummy.pdb"
/SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /MACHINE:X86 /ERRORREPORT:PROMPT nafxcw.lib
DelayImp.lib
<snip>
// WerleShowBug.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "WerleShowBug.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "WerleShowBugDoc.h"
#include "WerleShowBugView.h"
// #include <boost/utility.hpp>
#include <boost/function.hpp>
#include <boost/thread/detail/config.hpp>
#include <stdexcept>
namespace boost 
{
class BOOST_THREAD_DECL my_exception 
        : public std::exception 
{};
namespace detail {
class BOOST_THREAD_DECL tss // : private noncopyable
{
public:
    tss(boost::function1<void, void*>* pcleanup) {
        if (pcleanup == 0) 
                { 
                }
        try
        {
                // remove this code and it runs
            init(pcleanup);
                // 
        }
        catch (...)
        {
            delete pcleanup;
        }
    }
private:
    unsigned int m_slot; //This is a "pseudo-slot", not a native slot
    void init(boost::function1<void, void*>* pcleanup);
};
template <typename T>
struct tss_adapter
{
    template <typename F>
    tss_adapter(const F& cleanup) : m_cleanup(cleanup) { }
    void operator()(void* p) { m_cleanup(static_cast<T*>(p)); }
    boost::function1<void, T*> m_cleanup;
};
} // namespace detail
template <typename T>
class thread_specific_ptr // : private noncopyable
{
public:
    thread_specific_ptr()
        : m_tss(new boost::function1<void, void*>(
                    boost::detail::tss_adapter<T>(
                        &thread_specific_ptr<T>::cleanup)))
    {
    }
    thread_specific_ptr(void (*clean)(T*))
        : m_tss(new boost::function1<void, void*>(
                    boost::detail::tss_adapter<T>(clean)))
    {
    }
    ~thread_specific_ptr() { reset(); }
    T* get() const { return static_cast<T*>(m_tss.get()); }
    T* operator->() const { return get(); }
    T& operator*() const { return *get(); }
    T* release() { T* temp = get(); if (temp) m_tss.set(0); return temp; }
    void reset(T* p=0)
    {
//         T* cur = get();
//         if (cur == p) return;
//         m_tss.set(p);
//         if (cur) m_tss.cleanup(cur);
    }
private:
    static void cleanup(T* p) { delete p; }
    detail::tss m_tss;
};
#ifdef BOOST_MSVC
#   pragma warning(pop)
#endif
} // namespace boost
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CWerleShowBugApp
BEGIN_MESSAGE_MAP(CWerleShowBugApp, CWinApp)
        ON_COMMAND(ID_APP_ABOUT, &CWerleShowBugApp::OnAppAbout)
        // Standard file based document commands
        ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
        ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
        // Standard print setup command
        ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
// CWerleShowBugApp construction
CWerleShowBugApp::CWerleShowBugApp()
{
        // TODO: add construction code here,
        // Place all significant initialization in InitInstance
}
// The one and only CWerleShowBugApp object
CWerleShowBugApp theApp;
// CWerleShowBugApp initialization
BOOL CWerleShowBugApp::InitInstance()
{
        // This one killes the app
        static boost::thread_specific_ptr<void *> tld_helper;
        
        // InitCommonControlsEx() is required on Windows XP if an application
        // manifest specifies use of ComCtl32.dll version 6 or later to enable
        // visual styles.  Otherwise, any window creation will fail.
        INITCOMMONCONTROLSEX InitCtrls;
        InitCtrls.dwSize = sizeof(InitCtrls);
        // Set this to include all the common control classes you want to use
        // in your application.
        InitCtrls.dwICC = ICC_WIN95_CLASSES;
        InitCommonControlsEx(&InitCtrls);
        CWinApp::InitInstance();
        // Initialize OLE libraries
        if (!AfxOleInit())
        {
                AfxMessageBox(IDP_OLE_INIT_FAILED);
                return FALSE;
        }
        AfxEnableControlContainer();
        // Standard initialization
        // If you are not using these features and wish to reduce the size
        // of your final executable, you should remove from the following
        // the specific initialization routines you do not need
        // Change the registry key under which our settings are stored
        // TODO: You should modify this string to be something appropriate
        // such as the name of your company or organization
        SetRegistryKey(_T("Local AppWizard-Generated Applications"));
        LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)
        // Register the application's document templates.  Document templates
        //  serve as the connection between documents, frame windows and views
        CMultiDocTemplate* pDocTemplate;
        pDocTemplate = new CMultiDocTemplate(IDR_WerleShowBugTYPE,
                RUNTIME_CLASS(CWerleShowBugDoc),
                RUNTIME_CLASS(CChildFrame), // custom MDI child frame
                RUNTIME_CLASS(CWerleShowBugView));
        if (!pDocTemplate)
                return FALSE;
        AddDocTemplate(pDocTemplate);
        // create main MDI Frame window
        CMainFrame* pMainFrame = new CMainFrame;
        if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
        {
                delete pMainFrame;
                return FALSE;
        }
        m_pMainWnd = pMainFrame;
        // call DragAcceptFiles only if there's a suffix
        //  In an MDI app, this should occur immediately after setting m_pMainWnd
        // Enable drag/drop open
        m_pMainWnd->DragAcceptFiles();
        // Enable DDE Execute open
        EnableShellOpen();
        RegisterShellFileTypes(TRUE);
        // Parse command line for standard shell commands, DDE, file open
        CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);
        // Dispatch commands specified on the command line.  Will return FALSE if
        // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
        if (!ProcessShellCommand(cmdInfo))
                return FALSE;
        // The main window has been initialized, so show and update it
        pMainFrame->ShowWindow(m_nCmdShow);
        pMainFrame->UpdateWindow();
        return TRUE;
}
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
        CAboutDlg();
// Dialog Data
        enum { IDD = IDD_ABOUTBOX };
protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
// Implementation
protected:
        DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// App command to run the dialog
void CWerleShowBugApp::OnAppAbout()
{
        CAboutDlg aboutDlg;
        aboutDlg.DoModal();
}
// CWerleShowBugApp message handlers