Skip to contentSkip to conversation

Thread group exit problem reappeared.

PATCH New Dave McCracken 1 participant 1 message May 9, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Thread group exit problem reappeared.

A long time ago there was thread group code that at exit time tried to reparent a task to another task in the thread group. I discovered a major race condition in this code, and submitted a patch that removed it. This patch was accepted in, I thin, 2.4.12. The code reappeared in 2.4.18, breaking applications that use thread groups.

As part of chasing this down, I figured out a way to remove the race condition while still preserving this behavior. I've attached a patch against 2.4.19-pre8 that fixes it.

Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

./kernel/exit.c +9 -3
@@ -152,7 +152,7 @@
 
 /*
  * When we die, we re-parent all our children.
- * Try to give them to another thread in our process
+ * Try to give them to another thread in our thread
  * group, and if no such member exists, give it to
  * the global child reaper process (ie "init")
  */
@@ -162,8 +162,14 @@
 
 	read_lock(&tasklist_lock);
 
-	/* Next in our thread group */
-	reaper = next_thread(father);
+	/* Next in our thread group, if they're not already exiting */
+	reaper = father;
+	do {
+		reaper = next_thread(reaper);
+		if (!(reaper->flags & PF_EXITING))
+			break;
+	} while (reaper != father);
+
 	if (reaper == father)
 		reaper = child_reaper;