std::thread crashes with error "f:\dd\vctools\crt_bld\self_x86\crt\src\thr\mutex.cpp(206): unlock of unowned mutex" - by Sarang.Baheti

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


9
0
Sign in
to vote
ID 688797 Comments
Status Closed Workarounds
Type Bug Repros 6
Opened 9/16/2011 5:41:06 AM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

Description

Trying out the new thread library in C++. It seems the thread implementation is not bug-free. While trying to compute dotproduct with various threads I often run into this assertion:

"f:\dd\vctools\crt_bld\self_x86\crt\src\thr\mutex.cpp(206): unlock of unowned mutex"
Sign in to post a comment.
Posted by Sarang.Baheti on 1/20/2012 at 5:37 PM
Hello Stephan,

Thanks for fixing the issue.
When should I expect the update?

Thanks,
Sarang
Posted by Microsoft on 1/18/2012 at 8:53 PM
Hi,

Thanks again for reporting this bug. We've fixed it, and the fix will be available in VC11.

The problem was that we had some code unlocking a critical section, then setting a thread ID to -1, when it should have been the other way around.

As always, if you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 1/9/2012 at 6:10 PM
Hi,

Thanks for reporting this bug. We understand how serious it is, and we're investigating.

In the meantime, if you have any questions, feel free to E-mail me at stl@microsoft.com . (I am not currently aware of any workarounds.)

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by dmilos on 1/6/2012 at 4:39 AM
Simple consumer/producer implemented with conditional variable pop up this error immediately.
Posted by ashr1 on 12/4/2011 at 10:41 PM
Repro step for the code added earlier:
1. Put a breakpoint on the return statement.
2. Run in debug mode.
3. Once in a while the error won't occur but most of the times it would.
Posted by ashr1 on 12/4/2011 at 10:39 PM
This is with VS 2011 Developer preview.

Microsoft Visual Studio 11
Version 11.0.40825.2 PREREL
Microsoft Visual C++ 11 Developer Preview 01019-315-4422943-70461

Easy to repro as someone said below.
Another sample of repro code:

#include <iostream>
#include <thread>
#include <algorithm>
#include <vector>
int main()
{
    std::vector<std::thread> workers;
    for (int i=0; i< 10;++i)
    {
        workers.push_back(std::thread([i]()
        {
            std::cout << "Hi from thread! [" << i <<"] " << std::endl;
        }));
    }

    std::cout << "Hi from main thread!" <<std::endl;

    std::for_each(workers.begin(), workers.end(), [](std::thread & th)
    {
        th.join();
    });

    return 0;
}
Posted by Anonymous12839 on 11/30/2011 at 5:16 PM
WRT my last comment, it is surely racing somewhere and is hard to trigger while running under a debugger, but not so hard when not attached.
Posted by Anonymous12839 on 11/30/2011 at 5:14 PM
This is trivially reproducible by creating a short-running std::thread and immediately joining, but can take many iterations.
Posted by MS-Moderator09 [Feedback Moderator] on 9/18/2011 at 8:22 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Sarang.Baheti on 9/16/2011 at 8:22 AM
Thanks for looking into the matter. I think this issue is quite fundamental. I do not mean to be pessimistic but even with well factored code if we run into such issues I doubt if people would be able to get to do lot of interesting stuff.

Here [http://www.sarangbaheti.com/conceptualspace/2011/09/16/multithreading-in-c-part-1/] is the same example in C# code and it works great.

I hope this matter will be resolved at earliest.

Best,
Sarang
Posted by MS-Moderator01 on 9/16/2011 at 6:42 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)