Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
4993 Discussions

Thread Error Analysis: Intel Inspector and boost::thread::once.hpp corrupts stack

Gunther_L_
Beginner
332 Views

Hi!

I tried to use Intel Inspector (from XE 2015) with little success. The application I try to analyze uses boost threads and a boost spirit parser. Thread safety defines have been added (eg BOOST_SPIRIT_THREADSAFE).

The following example displays the problem. In normal Release/Debug builds the program will output :

$ build64/Debug/once_test.exe
construct()
construct()

 

If Intel Inspector XE 2015 is used with "Thread Error Analysisthe program fails with stack corruption during the execution of boost::call_once.

If Intel Inspector XE 2015 is used with "MemoryError Analysis" everything is ok.

Is this a bug? Why is it only triggered when using the "Thread Error Analysis" functionality?

Environment:

// Tools:
// Windows 7 64bit
// Intel Inspector XE 2015
// Visual Studio 2013 Update 4
// Boost 1.57.0:  boost/thread/once.hpp

 

Thanks a lot in advance!

 

Bye Gunther

// Example:

#include <boost/thread/once.hpp>
 
#include <iostream>
#include <assert.h>
 
//
// Small example showing the problem of:
// This example only crashes during analyzing runs with the Intel Inspector tool
// 
// Tools:
// Intel Inspector XE 2015
// Visual Studio 2013 Update 4
// Boost 1.57.0:  boost/thread/once.hpp
 
struct default_ctor
{
    static void construct()
    {
        std::cout << "construct()" << std::endl;
    }
};
 
 
 
//
// trying the same without boost
// but not reproducible
namespace not_boost
{
    struct once_flag
    {
        long status;
        long count;
    };
 
    void call_once(once_flagflagvoid(*f)())
    {
        assert(flag.status == 0);
        assert(flag.count == 0);
        f();
    }
 
    // Same signature as boost::call_once but use my once_flag type
    template <typename Function>
    inline void call_once(Function funconce_flagflag)
    {
        call_once(flagfunc);
    }
 
 
}
 
int main(int argccharargv)
{
 
    {
        static not_boost::once_flag constructed_ = {0};
 
        // does not triggers the stack error
        not_boost::call_once(&default_ctor::constructconstructed_);
    }
    {
        static boost::once_flag constructed_ = {0};
 
        // triggers error: the stack seems to be corrupted
        boost::call_once(&default_ctor::constructconstructed_);
    }
 
 
    return 0;
}
0 Kudos
1 Reply
Gunther_L_
Beginner
332 Views

I would like the test this using Intel Parallel Studio XE2013. Is there still a trial download available for it?

Edit:

Additional information:

When I switch the build to RelWithDebInfo or Release (+turning off optimizations)

Edit 2:

In fact:

It works if "Only __inline (/Ob1) option is set in the compiler settings. With this settings Inspector succeeds in Debug and Release builds.

 

 

Visual Studio 2013 C/C++ commandline is:

Debug.

/GS /TP /W3 /wd"4786" /wd"4250" /wd"4503" /Zc:wchar_t /I"opt\include\boost\boost-1_57"  /Zi /Gm- /Od /Ob0 /Fd"once_test.dir\Debug\vc120.pdb" /D "WIN32" /D "_WINDOWS" /D "NOMINMAX" /D "BUILD_X64" /D "_DEBUG" /D "BOOST_ALL_NO_LIB" /D "CMAKE_INTDIR=\"Debug\"" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /MDd /Fa"Debug/" /EHsc /nologo /Fo"once_test.dir\Debug\" /Fp"once_test.dir\Debug\once_test.pch" 

RelWithDebInfo:

/GS /TP /W3 /wd"4786" /wd"4250" /wd"4503" /Zc:wchar_t /I"opt\include\boost\boost-1_57"  /Zi /Gm- /Od /Ob1 /Fd"once_test.dir\RelWithDebInfo\vc120.pdb" /D "WIN32" /D "_WINDOWS" /D "NOMINMAX" /D "BUILD_X64" /D "NDEBUG" /D "BOOST_ALL_NO_LIB" /D "CMAKE_INTDIR=\"RelWithDebInfo\"" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /GR /Gd /MD /Fa"RelWithDebInfo/" /EHsc /nologo /Fo"once_test.dir\RelWithDebInfo\" /Fp"once_test.dir\RelWithDebInfo\once_test.pch" 

0 Kudos
Reply