[PATCH] Change llvm::sys::Mutex implementation to use STL-provided mutexes.
Aaron Ballman
aaron at aaronballman.com
Fri May 30 08:31:07 PDT 2014
Thank you for digging so deeply into this!
On Thu, May 29, 2014 at 8:23 PM, Zachary Turner <zturner at google.com> wrote:
> So, the issue is that std::mutex and std::recursive_mutex simply cannot be
> used during an atexit() handler. It still seems like a good drop-in
> replacement for the hand-rolled mutex in all other cases.
>
> This is not documented anywhere, but if you dig into the code you'll find
> that std::mutex and std::recursive_mutex are implemented using ConcRT
> (microsoft concurrency runtime), and it relies on a call to
> RegisterWaitForSingleObject(). That function in turn uses QueueUserAPC, and
> if you check the documentation you'll see that it says "When the thread is
> in the process of being terminated, calling QueueUserAPC to the thread's APC
> queue will fail with ERROR_GEN_FAILURE (31)".
>
> So, TL;DR - can't use mutexes from atexit handler. This seems like a
> reasonable restriction, as atexit handlers are probably pretty rare anyway.
I agree that this is a reasonable restriction.
> I will try to find a way to change the shutdown order to not rely on the
> atexit handler.
Sounds like a good approach.
~Aaron
More information about the llvm-commits
mailing list