ntdll: Fix race-condition when threads are killed during shutdown.

Sebastian Lackner sebastian at fds-team.de
Sat Feb 28 18:55:52 CST 2015


When exit_thread is executed, nb_threads is decremented before the thread is
fully shutdown. When another thread runs ExitProcess() this will cause a SIGQUIT
signal to all threads, effectively decrementing nb_threads twice. The process
will terminate with a wrong exitcode then because the refcount reaches zero too
early. This is actually also the reason why I added the Sleep(...) at the end in
one of my previous patches, I noticed that the exitcode is zero even if tests fail.

Currently Wine has no locking protection of LdrShutdownProcess(), so it can
only be executed safely when all other threads have terminated before. Most
likely there are more Wine bugs in this area (unlikely that it works that way on
Windows), but the attached patch should fix the most critical one (messed up
refcounting of threads) for now. It has the side effect that under specific
circumstances LdrShutdownProcess is never executed, but thats still way better
than before.

I'm also open for other suggestions if someone has a better idea how to fix that.

---
 dlls/ntdll/thread.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ntdll-Fix-race-condition-when-threads-are-killed-dur.patch
Type: text/x-patch
Size: 1571 bytes
Desc: not available
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20150301/65ed0cb7/attachment.bin>


More information about the wine-patches mailing list