Files
llvm-project/llvm/lib/Support/Parallel.cpp
Maurice Heumann 8b77480a48 [Support] Join threads when stopping ThreadPoolExecutor (#166054)
When building LLVM as DLL, the `ThreadPoolExecutor` can cause deadlocks
on Windows.

The threads were previously only joined when the destructor of the
`ThreadPoolExecutor` is called, not when it's stopped. Destruction
happens when unloading the DLL, when the global destructors are called.

On Windows, `std::thread` uses `FreeLibraryAndExitThread` to cleanup a
thread. This requires access to the loader lock, when a thread
terminates. However, when destroying the pool, the loader lock is also
held, as the DLL is being unloaded. If the threads did not end fast
enough, the destructor would wait for them to join. At the same time,
the threads would wait for the destructor to release the loader lock.

Joining the threads when stopping the pool fixes that, as it ensures the
threads are stopped when calling `llvm_shutdown`, outside the loader
lock.
2026-01-19 14:43:35 +00:00

8.4 KiB