Some background: I am trying to track a bug which is causing me major headaches. After many dead ends (see this question) I finally ended up with this code:
#include <thread>
#include <vector>
#include <iosfwd>
#include <sstream>
#include <string>
#include <windows.h>
int main()
{
SRWLOCK srwl;
InitializeSRWLock(&srwl);
for(size_t i=0;i<1000;++i)
{
std::vector<std::thread>threads;
for(size_t j=0;j<100;++j)
{
OutputDebugString(".");
threads.emplace_back([&](){
AcquireSRWLockExclusive(&srwl);
//Code below modifies the probability to see the bug.
std::this_thread::sleep_for(std::chrono::microseconds(1));
std::wstringstream wss;
wss<<std::this_thread::get_id();
wss.str();
//Code above modifies the probability to see the bug.
ReleaseSRWLockExclusive(&srwl);});
}
for(auto&t:threads){t.join();}
OutputDebugString((std::to_string(i)+"\n").data());
}
return 0;
}
When I run this code inside VS 2013 debugger the program hangs with an output like this one:
....................................................................................................0
....................................................................................................1
....................................................................................................2
...........................
Strangely enough, If I pause the debugger and inspect what is going on, one of the threads is inside AcquireSRWLockExclusive (in NtWaitForAlertByThreadId) apparently there is no reason why the program is hanging. When I click resume, the program happily continues and print some more stuff until it is blocked again.
Do you have any Idea what is going on here ?
Some more info:
Just go to File->Open->Project/Solution and browse to the .exe file. Like you would if it was a . sln file. Visual Studio will then open that EXE as a project.
To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.
The most common problem is that you did not set up launch.json or there is a syntax error in that file. Alternatively, you might need to open a folder, since no-folder debugging does not support launch configurations.
This issue is caused by an OS scheduler bug introduced in the spring 2014 update to Windows 8.1. A hotfix for this problem was released in May 2015 and available at https://support.microsoft.com/en-us/kb/3036169.
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