summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Strauman <strauman@slac.stanford.edu>2013-12-17 16:59:38 -0600
committerGedare Bloom <gedare@rtems.org>2014-04-11 15:44:15 -0400
commit44c3ffbba70551f4a64d7facdbd6610cc066f9fa (patch)
tree81ebc8450ea04385afb8f704630070236b8d58ab
parentAdd c++ guard to header. (diff)
downloadrtems-44c3ffbba70551f4a64d7facdbd6610cc066f9fa.tar.bz2
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.
-rw-r--r--cpukit/posix/src/pthreadcreate.c19
1 files 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
*/