[PATCH] D102684: [LLD] Allow disabling the early exit codepath as a build configuration

Adrian McCarthy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 21 14:58:25 PDT 2021


amccarth added a comment.

In D102684#2773342 <https://reviews.llvm.org/D102684#2773342>, @andrewng wrote:

> I looked into this in some detail back in the day and am mainly responsible for how this thread pool currently functions. I primarily focused on static linking with the MSVC static runtime, as that's what we use downstream and were seeing issues with, but also included MinGW, GNU and libc++. To be honest, I can't remember if I tried LLVM_LINK_LLVM_DYLIB, there are just too many possible configurations! The various compilers/runtimes have changed since I last looked at this code, so it's not surprising that there may be issues depending on your configuration.
>
> From past experience, I think it has always been "dangerous" on Windows to exit without waiting/terminating any running threads. If this can't be done, then a "hard" exit, e.g. via ExitProcess(), is usually the only reliable way to finish....

Agreed.  ExitProcess is usually the best choice when you don't want to bother with an orderly shut down.  I'd go so far as to say that if you experience a deadlock or other problem with ExitProcess, the code likely has a bug or at least a questionable design choice.  For example, hanging in a destructor in DLL_PROCESS_DETACH is akin to throwing an exception from a destructor:  You shouldn't do that.

> The other thing that complicates the situation is that LLD can exit from a thread from the thread pool in certain error cases, i.e. doesn't always exit from the main thread. This scenario is going to be rare in actual practical use, but AFAIK is still a path exercised by the LLD testing.

I could see how that might make even ExitProcess a risky proposition if there are any waits on synchronization objects happening during DLL_THREAD_DETACH.  Is this a well understood scenario?  If the DLL_THREAD_DETACH destructor problems are hard to fix, would it be feasible to have the thread pool thread signal the main thread to have _it_ call ExitProcess?

Windows has evolved the shutdown rules to reduce the risk of deadlocking in DLL_THREAD_DETACH, but it's not perfect.  https://devblogs.microsoft.com/oldnewthing/20100122-00/?p=15193


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102684



More information about the llvm-commits mailing list