@@ -475,6 +475,65 @@ int pthread_join( pthread_t pthread,
475475
476476/*-----------------------------------------------------------*/
477477
478+ int pthread_detach (pthread_t pthread )
479+ {
480+ int iStatus = 0 ;
481+ pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread ;
482+ eTaskState pThreadState ;
483+
484+ /* Make sure pthread is joinable. */
485+ if ( !pthreadIS_JOINABLE ( pxThread -> xAttr .usSchedPriorityDetachState ) )
486+ {
487+ iStatus = EINVAL ;
488+ }
489+
490+ if ( iStatus == 0 )
491+ {
492+ /* Create a critical section to verify that pthread is joinable. */
493+ vTaskSuspendAll ();
494+
495+ pThreadState = eTaskGetState (pxThread -> xTaskHandle );
496+
497+ /* Thread has been deleted or is invalid. */
498+ if ( (pThreadState == eDeleted ) || (pThreadState == eInvalid ) )
499+ {
500+ iStatus = EINVAL ;
501+ }
502+ else
503+ {
504+ /* Release xJoinBarrier and delete it. */
505+ ( void ) xSemaphoreGive ( ( SemaphoreHandle_t ) & pxThread -> xJoinBarrier );
506+ vSemaphoreDelete ( ( SemaphoreHandle_t ) & pxThread -> xJoinBarrier );
507+
508+ /* Release xJoinMutex and delete it. */
509+ ( void ) xSemaphoreGive ( ( SemaphoreHandle_t ) & pxThread -> xJoinMutex );
510+ vSemaphoreDelete ( ( SemaphoreHandle_t ) & pxThread -> xJoinMutex );
511+
512+ /* Thread has been finished */
513+ if ( pThreadState == eSuspended )
514+ {
515+ /* Delete the FreeRTOS task that ran the thread. */
516+ vTaskDelete ( pxThread -> xTaskHandle );
517+
518+ /* Free the thread object. */
519+ vPortFree ( pxThread );
520+ }
521+ else
522+ {
523+ /* Thread is in the running or ready state. */
524+ pthread_attr_setdetachstate ( (pthread_attr_t * ) & pxThread -> xAttr , PTHREAD_CREATE_DETACHED );
525+ }
526+ }
527+
528+ /* End the critical section. */
529+ xTaskResumeAll ();
530+ }
531+
532+ return iStatus ;
533+ }
534+
535+ /*-----------------------------------------------------------*/
536+
478537pthread_t pthread_self ( void )
479538{
480539 /* Return a reference to this pthread object, which is stored in the
0 commit comments