8

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;
}
6
  • 3
    clang -stdlib=libc++ -std=c++11 compiles and prints out "derived". What is the error you're seeing? Mar 29, 2012 at 14:00
  • g++ -std=c++0x -lpthread also compiles and eventhough I don't see any direct use for polymorphic threads, there is nothing evil about it.
    – stefaanv
    Mar 29, 2012 at 14:14
  • Thanks for your help, guys. I'll file a bug on VS and, hopefully, they'll confirm.
    – screwnut
    Mar 29, 2012 at 18:20
  • @Howard Hinnant That line triggers 6 errors in two lines of <xrefwrap>. I normally don't shy away from reading STL implementation headers, but here, the line where the first error occurs is impenetrable to me, it's a makeshift variadic template macro. The first error is pretty basic: "'base' : cannot instantiate abstract class". The second error is: "use of undefined type 'std::_Result_of0<_Fty>' where _Fty=base (void)". The rest of the errors are just fallout from the first two, I believe.
    – screwnut
    Mar 29, 2012 at 18:27
  • 2
    @screwnut: Definitely a bug. Once you file the bug, post an answer with a link to it so you can close the question.
    – GManNickG
    Mar 29, 2012 at 20:32

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.