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.
This commit is contained in:
Till Strauman
2013-12-17 16:59:38 -06:00
committed by Gedare Bloom
parent 765ae93bdb
commit 44c3ffbba7

View File

@@ -237,6 +237,8 @@ int pthread_create(
* POSIX threads are allocated and started in one operation. * POSIX threads are allocated and started in one operation.
*/ */
_Thread_Disable_dispatch();
status = _Thread_Start( status = _Thread_Start(
the_thread, the_thread,
THREAD_START_POINTER, THREAD_START_POINTER,
@@ -245,13 +247,6 @@ int pthread_create(
0 /* unused */ 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 * _Thread_Start only fails if the thread was in the incorrect state
* *
@@ -260,11 +255,21 @@ int pthread_create(
*/ */
if ( !status ) { if ( !status ) {
_Thread_Enable_dispatch();
_POSIX_Threads_Free( the_thread ); _POSIX_Threads_Free( the_thread );
_RTEMS_Unlock_allocator(); _RTEMS_Unlock_allocator();
return EINVAL; 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 * Return the id and indicate we successfully created the thread
*/ */