summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/threadrestart.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-16 12:05:42 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-16 12:46:48 +0200
commit4b3251adda40e73593eae23b9d4f49643212a7d3 (patch)
tree06f333b73bf4e7c41d4a7ff79a64f96bb4d130dc /cpukit/score/src/threadrestart.c
parentrtems: Fix rtems_semaphore_create() (diff)
downloadrtems-4b3251adda40e73593eae23b9d4f49643212a7d3.tar.bz2
score: Fix thread delete race condition on SMP
Diffstat (limited to 'cpukit/score/src/threadrestart.c')
-rw-r--r--cpukit/score/src/threadrestart.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index f155980c1a..21e260b10b 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 )