<div dir="ltr">As part of my effort to replace our hand-rolled mutexes with std::mutex and std::recursive_mutex, I found that many of the tests were failing on Windows after doing the replacement.  One of the reasons was due to the use of a mutex in lib\Support\CrashRecoveryContext.cpp.  If this mutex is an std::recursive_mutex or std::mutex, tests fail.  If this mutex is a windows CRITICAL_SECTION, the tests pass.<div>
<br></div><div>I *think*, but am not 100% sure, that this is due to an interaction between MSVC's mutex implementation and the use of vectored exception handling.  </div><div><br></div><div>There is a comment in this file that says the following:</div>
<div><br></div><div><div>// On Windows, we can make use of vectored exception handling to</div><div>// catch most crashing situations.  Note that this does mean</div><div>// we will be alerted of exceptions *before* structured exception</div>
<div>// handling has the opportunity to catch it.  But that isn't likely</div><div>// to cause problems because nowhere in the project is SEH being</div><div>// used.</div></div><div><br></div><div>However, my understanding is that the handler specified to AddVectoredExceptionHandler will get called for EVERYTHING.  In particular, since we install the handler at the front of the list, if some internal Windows library wrote something like this:</div>
<div><br></div><div>__try {</div><div>} except (...) {</div><div>  // handle exception</div><div>}</div><div><br></div><div>Then our handler would get called before the Windows handler.  Furthermore, we seem to assume inside the handler that it's impossible to reach the handler unless there was an actual crash scenario.  Is this necessarily true?</div>
<div><br></div><div>It's worth pointing out that std::[recursive_]mutex on MSVC are implemented using ConcRT (Microsoft Concurrency Runtime), which is all sorts of crazy (even has its own user mode scheduler [1]), so I think the user of a vectored exception handler is not safe with ConcRT.</div>
<div><br></div><div>Any other windows experts have any thoughts into what might be going on here?  <br></div><div><br></div><div>[1] - <a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx">http://blogs.msdn.com/b/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx</a><br>
</div></div>