Boost: thread disables microsoft C ++ compiler

A short version of my question:

This code causes the compiler to crash.

pThread[0] = new boost::thread(
boost::bind(
    &cGridAnimator::DoJob,  // member function
       this ),                 // instance of class
       0 );                 // job number

      

The compiler crashed when trying to compile this code. (It's not my program that crashe when I run this code!)

What needs to be fixed?


Long version of the question

I split my work on a large 3D network into 8 separate jobs that need to be run on separate threads in order to use the 8 core machine.

This works great:

    JOB_LOOP {
        pThread[kjob] = new boost::thread( ::DoJob, kjob );
    }

      

The global free DoJob function reads data from the global cGridAnimator instance according to the job number.

However, I don't like all these globals, and I don't like using so many accessors to get the data I need. It would be much cleaner to use the cGridAnimator method.

Hence the code at the top of this question.

However, when I compile it on MSVC ++ 2008, the compiler gives the following complaints and then crashes.

1>Compiling...
1>mfm1.cpp
1>C:\Program Files\boost\boost_1_38_0\boost/bind.hpp(1643) : warning C4180: qualifier applied to function type has no meaning; ignored
1>        C:\Program Files\boost\boost_1_38_0\boost/bind.hpp(1677) : see reference to class template instantiation 'boost::_bi::add_cref<Pm,I>' being compiled
1>        with
1>        [
1>            Pm=void (__thiscall cGridAnimator::* )(int),
1>            I=1
1>        ]
1>        .\mfm1.cpp(158) : see reference to class template instantiation 'boost::_bi::dm_result<Pm,A1>' being compiled
1>        with
1>        [
1>            Pm=void (__thiscall cGridAnimator::* )(int),
1>            A1=cGridAnimator *
1>        ]
1>C:\Program Files\boost\boost_1_38_0\boost/mem_fn.hpp(318) : warning C4180: qualifier applied to function type has no meaning; ignored
1>        C:\Program Files\boost\boost_1_38_0\boost/bind/bind_template.hpp(344) : see reference to class template instantiation 'boost::_mfi::dm<R,T>' being compiled
1>        with
1>        [
1>            R=void (int),
1>            T=cGridAnimator
1>        ]
1>Project : error PRJ0002 : Error result 1 returned from 'C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe'.

      

+2


source to share


3 answers


Change your code to:

pThread[0] = new boost::thread(boost::bind(&cGridAnimator::DoJob, this, 0 ));  

      



This code provides a function void (void)

for the stream instead of a function, void (int)

and an additional argument.

+3


source


There is no definitive answer; in general, ICE is always a good reason to contact your compiler vendor.

To find the real cause, it helps to try to find the minimal program that is still showing crash. This means removing as much code as possible, removing as many dependencies as possible, etc. Etc. For one ICE, I was once successful in starting a new project and was just writing fifty lines of code where I suspected the problem.



Workarounds have helped me in the past:

  • reduce optimization level
    • especially the timecode code generation seems to be a bit wobbly.
  • change the order of incoming files
    • only sane if you know revisiting the source when it stops working, so you can focus on the changes there
  • switch to a different boost version
    • the author of the accelerated library may have activated a workaround, or the code just changed enough so that it doesn't call ICE anymore.
+2


source


Note, if you are using boost :: bind and the parameter type is wrong, Visual Studio will not remind you of this error, but the error with PRJ0002 and cl.exe

0


source







All Articles