Ok.. First of all, I have to say I’m using BOOST with its source (I have to).
I’m both a BOOST and a C++ newbie, but I’m not new to coding (I’m rather used to managed languages). I met this problem in a somewhat large project, then I reproduced it in this little code snippet I’m presenting here:
#include <boost/thread.hpp>
void foo(int bar) {
printf("Chu %d!",bar);
}
int main() {
boost::thread_attributes attrs;
boost::thread causeTrouble(attrs,foo,42); // <-- Probably problematic line
causeTrouble.join();
}
According to BOOST 1.52.0 Documentation this snippet should both compile and run fine; however, it gives me a weird compilation problem in a BOOST library header file (no other errors or warnings are present):
<boost_path>/bind/bind.hpp:313: error: no match for call to '(boost::thread_attributes) (void (*&)(int), int&)
To me, it looks like there’s no actual boost::thread(boost::thread_attributes,F f) constructor, even if it should be according to the previously linked documentation.
Anyway, what’s funny is that both the following lines do compile fine:
boost::thread noTrouble(attrs,foo);
and
boost::thread noTroubleEither(foo,42);
Even if I thoroughly searched StackOverflow and the rest of the Internet, I don’t know where to turn my head 🙁 In fact this is the first time I’m forced to actually ask a new question. Help!
You say,
That’s not the constructor you’re trying to call though. You’re calling
boost::thread(attrs, foo, 42). Based off the link, it looks like there’s noboost::thread(boost::attributes, F, Args)constructor implemented, hence the complaint.Try first using
boost::bindexplicitly to bind the42intofooand the starting the thread on the bound function object.Something like this: