Search

Creating threads using std::thread class causes application crash by Mladen Jankovic

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 726398
Opened: 2/23/2012 11:23:38 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
1
User(s) can reproduce this bug
When std::thread class is used to create more then one thread it causes to application to crash. Sometimes it throws exception, sometimes it causes access violation and sometimes it works.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 11 Developer Preview

Steps to reproduce

Code sample that causes crash:

#include <iostream>
#include <thread>
#include <vector>

#include <Windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
std::vector<std::thread*> threads;
for(int i = 0; i < 10; i++)
{
    threads.push_back(new std::thread([i] { std::cout << "thread " << i << std::endl; }));
}

for(int i = 0; i < 10; i++)
{
    threads[i]->join();
    delete threads[i];
}

return 0;
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Throws random exception like this:

thread 0
thread 1
thread 3
f:\dd\vctools\crt_bld\self_x86\crt\src\thr\mutex.cpp(206): unlock of unowned
mutex
thread 5
thread 4
thread 2

or causes access violation at mutex.cpp(218). Sometimes it crashes at other random placese, but not very often and sometimes it works without crashing

Expected results

thread 0
thread 1
thread 3
thread 5
thread 4
thread 2
thread 6
thread 8
thread 7
thread 9
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/27/2012 at 1:14 PM
Hi,

Thanks for reporting this bug. We've already fixed it in the VC11 Beta, which will be available on Feb 29.

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 MS-Moderator08 [Feedback Moderator] on 2/23/2012 at 6:58 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 investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 2/23/2012 at 11:45 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)
Posted by Mladen Jankovic on 2/23/2012 at 11:26 AM
It doesn't matter whether the static or dynamic runtime libraries are used.
Sign in to post a workaround.