mirror of
https://github.com/FreeRTOS/Lab-Project-FreeRTOS-POSIX.git
synced 2025-10-17 15:42:28 +08:00
Fix detach race condition (#43)
* Fix detach race condition pxThread->xAttr.usSchedPriorityDetachState may be changed by pthread_detach(). Suspend scheduler to prevent race condition. Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn> * Fix compiler warnings --------- Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn> Co-authored-by: wangfei_chen <wangfei_chen@realsil.com.cn> Co-authored-by: Rahul Kar <karahulx@amazon.com>
This commit is contained in:
@@ -101,10 +101,13 @@ static void prvExitThread( void )
|
||||
{
|
||||
pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread_self();
|
||||
|
||||
vTaskSuspendAll();
|
||||
|
||||
/* If this thread is joinable, wait for a call to pthread_join. */
|
||||
if( pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) )
|
||||
{
|
||||
( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxThread->xJoinBarrier );
|
||||
( void ) xTaskResumeAll();
|
||||
|
||||
/* Suspend until the call to pthread_join. The caller of pthread_join
|
||||
* will perform cleanup. */
|
||||
@@ -112,6 +115,7 @@ static void prvExitThread( void )
|
||||
}
|
||||
else
|
||||
{
|
||||
( void ) xTaskResumeAll();
|
||||
/* For a detached thread, perform cleanup of thread object. */
|
||||
vPortFree( pxThread );
|
||||
vTaskDelete( NULL );
|
||||
@@ -359,7 +363,7 @@ int pthread_create( pthread_t * thread,
|
||||
}
|
||||
|
||||
/* End the critical section. */
|
||||
xTaskResumeAll();
|
||||
( void ) xTaskResumeAll();
|
||||
}
|
||||
|
||||
return iStatus;
|
||||
@@ -467,7 +471,7 @@ int pthread_join( pthread_t pthread,
|
||||
vPortFree( pxThread );
|
||||
|
||||
/* End the critical section. */
|
||||
xTaskResumeAll();
|
||||
( void ) xTaskResumeAll();
|
||||
}
|
||||
|
||||
return iStatus;
|
||||
@@ -526,7 +530,7 @@ int pthread_detach(pthread_t pthread)
|
||||
}
|
||||
|
||||
/* End the critical section. */
|
||||
xTaskResumeAll();
|
||||
( void ) xTaskResumeAll();
|
||||
}
|
||||
|
||||
return iStatus;
|
||||
|
Reference in New Issue
Block a user