This looks okay but it's not the first time we have to tweak dinput internal thread because of various deadlock situations.
Hopefully this would work but there's a case where it wouldn't: if an application module releases its last DInput reference while holding the loader lock (ie: within DllMain), in this case we'll deadlock as `FreeLibraryAndExitThread` will also need the loader lock.
I'm going to assume that this isn't an issue, but if I'm proved wrong we would need another way to signal and wait for the thread's exit.