[rtems commit] score: Fix thread delete race condition on SMP
Sebastian Huber
sebh at rtems.org
Thu Jun 16 10:47:29 UTC 2016
Module: rtems
Branch: master
Commit: 4b3251adda40e73593eae23b9d4f49643212a7d3
Changeset: http://git.rtems.org/rtems/commit/?id=4b3251adda40e73593eae23b9d4f49643212a7d3
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Jun 16 12:05:42 2016 +0200
score: Fix thread delete race condition on SMP
---
cpukit/score/src/threadrestart.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index f155980..21e260b 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -135,11 +135,19 @@ static void _Thread_Wake_up_joining_threads( Thread_Control *the_thread )
);
}
-static void _Thread_Make_zombie( Thread_Control *the_thread )
+static void _Thread_Add_to_zombie_chain( Thread_Control *the_thread )
{
ISR_lock_Context lock_context;
Thread_Zombie_control *zombies;
+ zombies = &_Thread_Zombies;
+ _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
+ _Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node );
+ _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
+}
+
+static void _Thread_Make_zombie( Thread_Control *the_thread )
+{
if ( _Thread_Owns_resources( the_thread ) ) {
_Terminate(
INTERNAL_ERROR_CORE,
@@ -153,15 +161,18 @@ static void _Thread_Make_zombie( Thread_Control *the_thread )
&the_thread->Object
);
- _Thread_Wake_up_joining_threads( the_thread );
_Thread_Set_state( the_thread, STATES_ZOMBIE );
_Thread_queue_Extract_with_proxy( the_thread );
_Thread_Timer_remove( the_thread );
- zombies = &_Thread_Zombies;
- _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
- _Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node );
- _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
+ /*
+ * Add the thread to the thread zombie chain before we wake up joining
+ * threads, so that they are able to clean up the thread immediately. This
+ * matters for SMP configurations.
+ */
+ _Thread_Add_to_zombie_chain( the_thread );
+
+ _Thread_Wake_up_joining_threads( the_thread );
}
static void _Thread_Free( Thread_Control *the_thread )
More information about the vc
mailing list