From 714156d7ab1c07c1bc4ee51de154fd7c7a473821 Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Tue, 13 Aug 2002 18:24:27 +0000
Subject: [PATCH] Fixed race condition when a thread gets killed right after
 starting.

---
 scheduler/client.c | 2 +-
 server/request.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scheduler/client.c b/scheduler/client.c
index cc95af31e29..c5379aa384c 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -680,6 +680,7 @@ void CLIENT_InitThread(void)
     wine_server_send_fd( reply_pipe[1] );
     wine_server_send_fd( teb->wait_fd[1] );
     teb->reply_fd = reply_pipe[0];
+    close( reply_pipe[1] );
 
     /* set close on exec flag */
     fcntl( teb->reply_fd, F_SETFD, 1 );
@@ -699,7 +700,6 @@ void CLIENT_InitThread(void)
         version  = reply->version;
         if (reply->boot) boot_thread_id = teb->tid;
         else if (boot_thread_id == teb->tid) boot_thread_id = 0;
-        close( reply_pipe[1] );
     }
     SERVER_END_REQ;
 
diff --git a/server/request.c b/server/request.c
index 855e8775608..36257c680bf 100644
--- a/server/request.c
+++ b/server/request.c
@@ -341,7 +341,7 @@ int receive_fd( struct process *process )
         if (data.tid) thread = get_thread_from_id( data.tid );
         else thread = (struct thread *)grab_object( process->thread_list );
 
-        if (!thread || thread->process != process)
+        if (!thread || thread->process != process || thread->state == TERMINATED)
         {
             if (debug_level)
                 fprintf( stderr, "%08x: *fd* %d <- %d bad thread id\n",
-- 
GitLab