<div dir="ltr">As part of a larger effort to replace LLVM's mutexes with std::mutex / std::recursive_mutex (which might end up being stalled for other reasons, but let's just assume it will move forward for the purposes of this discussion), I found that MSVC's implementation of std mutexes cannot be run during an atexit handler.  They simply don't work.  This led to a deadlock in this function when I used a std mutex.  <div>
<br></div><div>At a higher level, it seems fundamentally wrong to even be trying to acquire a mutex during thread shutdown anyway, so I was trying to remove this mutex entirely.  I suspect it happens because someone calls exit() (maybe indirectly through a call to report_fatal_error) while multiple threads were running.  </div>
<div><br></div><div>If it's only the preamble file, maybe it's possible to remove this file without acquiring a mutex.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 20, 2014 at 1:57 PM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div class=""><blockquote type="cite"><div>On Jun 19, 2014, at 5:08 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:</div>
<br><div><div dir="ltr">Actually, upon closer inspection, nobody even adds any temporary files to this.  Ever.</div></div></blockquote><div><br></div></div><div>ASTUnit::addTemporaryFile doesn’t seem that is getting used, but ASTUnit itself calls ‘setPreambleFile()’ which registers the precompiled preamble file with OnDiskData to be removed.</div>
<div><br></div><div>What are you trying to fix ?</div><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr">   Is this used for some kind of out-of-tree support?   If so, it seems reasonable to require that anyone who wants this implement this in their own code.  Maybe clang shouldn't even have this.  <div>

<br></div><div>Does anyone depend on this functionality and object to me deleting it?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 19, 2014 at 5:02 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Question for the wider list: Can someone explain ASTUnit's use temporary files?  Do we only ever open the files once and then that's it?  Or is there a chance of passing the filename around to someone else, who will then try to open it again?  Are these normal temporary files, in the sense that they're expected to be always closed on process exit?</div>


<div><br></div>Question for Argyrios: I'm looking at a fairly old revision you submitted, r159664.  The commit message here is as follows:<div><br></div><div><div>    [libclang] Protect against a race condition where a thread</div>


<div>    may be destroying an ASTUnit while cleanupOnDiskMapAtExit is</div><div>    getting called.</div><div><br></div><div>    <a>rdar://11781241</a></div><div><br></div></div><div>Unfortunately I can't see this rdar link, so I don't have any more context.  Can you elaborate on this race condition?  My guess is that we're running multiple threads, someone calls ::exit(), and then the running threads race against this atexit handler.</div>


<div><br></div><div>I'd like to fix this "properly", but it's difficult without have more context about this race.</div><div><br></div><div><br></div></div>
</blockquote></div><br></div>
</div></blockquote></div></div></div><br></div></blockquote></div><br></div>