Skip to content

Commit 2f9ab75

Browse files
author
wangfei_chen
committed
Fix detach race condition
pxThread->xAttr.usSchedPriorityDetachState may be changed by pthread_detach(). Suspend scheduler to prevent race condition. Signed-off-by: wangfei_chen <[email protected]>
1 parent 1bb2a09 commit 2f9ab75

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,20 @@ static void prvExitThread( void )
101101
{
102102
pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread_self();
103103

104+
vTaskSuspendAll();
104105
/* If this thread is joinable, wait for a call to pthread_join. */
105106
if( pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) )
106107
{
107108
( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxThread->xJoinBarrier );
109+
( void ) xTaskResumeAll();
108110

109111
/* Suspend until the call to pthread_join. The caller of pthread_join
110112
* will perform cleanup. */
111113
vTaskSuspend( NULL );
112114
}
113115
else
114116
{
117+
( void ) xTaskResumeAll();
115118
/* For a detached thread, perform cleanup of thread object. */
116119
vPortFree( pxThread );
117120
vTaskDelete( NULL );

0 commit comments

Comments
 (0)