From 44c3ffbba70551f4a64d7facdbd6610cc066f9fa Mon Sep 17 00:00:00 2001 From: Till Strauman Date: Tue, 17 Dec 2013 16:59:38 -0600 Subject: 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 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c index 69feb1e0c3..90e876cc84 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 */ -- cgit v1.2.3