I've observed a difference in behavior between the new library in Visual Studio 11 Beta and Boost with thread() and ref(). I'm wondering who is right. It could be both if the standard deviated from Boost's original implementation. (But I'm not about to try to decipher standardese...)
I would've tried it with MinGW... Alas, AFAIK, <thread> doesn't work for MinGW.
So, first question is, do gcc and Clang exhibit the same compilation failure? If they don't, I'll file a bug against VS. The second question might be, if that compilation failure is correct, what's my workaround to get what Boost gave me (short of keep using Boost)?
And I suppose I do have have a third question... Is what I'm doing even kosher to begin with?
class base
{
public:
virtual void operator()() = 0;
};
class derived : public base
{
public:
virtual void operator()()
{
cout << "derived" << endl;
}
};
int main()
{
base *b = new derived;
std::thread t(std::ref(*b)); // Nasty compilation errors.
boost::thread t(boost::ref(*b)); // Works fine.
t.join();
return 0;
}
I filed a bug against Visual Studio 11 Beta here. No status yet. Will edit this post with status when I get it.
Edit: Fixed in VS 2015 RTM, as per the update in the bug report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With