[rtems commit] posix: fix race condition between pthread_create and capture engine

Gedare Bloom gedare at rtems.org
Fri Apr 11 19:37:10 UTC 2014


Module:    rtems
Branch:    4.9
Commit:    44c3ffbba70551f4a64d7facdbd6610cc066f9fa
Changeset: http://git.rtems.org/rtems/commit/?id=44c3ffbba70551f4a64d7facdbd6610cc066f9fa

Author:    Till Strauman <strauman at slac.stanford.edu>
Date:      Tue Dec 17 16:59:38 2013 -0600

posix: fix race condition between pthread_create and capture engine

Fix PR 2068:
Reproducable crashes occur when using pthreads and the capture engine
at the same time. 'pthread_create()' is the culprit. It creates a SCORE thread
and then calls Thread_Start( ) without disabling thread-dispatching.

---

 cpukit/posix/src/pthreadcreate.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 69feb1e..90e876c 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -237,6 +237,8 @@ int pthread_create(
    *  POSIX threads are allocated and started in one operation.
    */
 
+  _Thread_Disable_dispatch();
+
   status = _Thread_Start(
     the_thread,
     THREAD_START_POINTER,
@@ -245,13 +247,6 @@ int pthread_create(
     0                     /* unused */
   );
 
-  if ( schedpolicy == SCHED_SPORADIC ) {
-    _Watchdog_Insert_ticks(
-      &api->Sporadic_timer,
-      _Timespec_To_ticks( &api->schedparam.ss_replenish_period )
-    );
-  }
-
   /*
    *  _Thread_Start only fails if the thread was in the incorrect state
    *  
@@ -260,11 +255,21 @@ int pthread_create(
    */
 
   if ( !status ) {
+    _Thread_Enable_dispatch();
     _POSIX_Threads_Free( the_thread );
     _RTEMS_Unlock_allocator();
     return EINVAL;
   }
 
+  if ( schedpolicy == SCHED_SPORADIC ) {
+    _Watchdog_Insert_ticks(
+      &api->Sporadic_timer,
+      _Timespec_To_ticks( &api->schedparam.ss_replenish_period )
+    );
+  }
+
+  _Thread_Enable_dispatch();
+
   /*
    *  Return the id and indicate we successfully created the thread
    */




More information about the vc mailing list