[PATCH] D73281: [LLD] Avoid exiting with a locked mutex NFC

Andrew Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 02:51:46 PST 2020


andrewng marked an inline comment as done.
andrewng added a comment.

It is generally not good practice to hold a lock whilst exiting, as this has the potential to cause deadlocks. I don't believe that this situation can occur currently with LLD. However, after some recent observations, it appears that on Windows, in particular when using the static run-time, the only guaranteed way to not intermittently crash on exit is to wait for all threads to terminate (see related review D70447 <https://reviews.llvm.org/D70447>). Doing so would enable this deadlock situation to occur.



================
Comment at: lld/Common/ErrorHandler.cpp:66
+  {
+    std::lock_guard<std::mutex> lock(mu);
+    lld::outs().flush();
----------------
MaskRay wrote:
> it does not seem that `exitLld` can be invoked concurrently.
Yes, indeed that is another potential problem that exists and I believe that multiple threads calling _exit is also undefined behaviour.

However, this change is really to protect against flushing the streams whilst some other thread could be writing to them.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73281/new/

https://reviews.llvm.org/D73281





More information about the llvm-commits mailing list