From 14f39129227574cbbff1152c3246fece02c68a2a Mon Sep 17 00:00:00 2001 From: David Chalco Date: Fri, 21 Feb 2020 18:59:26 +0000 Subject: [PATCH 1/7] handle pthread_join(null), implement pthread_cancel with tests --- .../FreeRTOSConfig.h | 2 +- .../source/FreeRTOS_POSIX_pthread.c | 49 +++++- .../lib/include/FreeRTOS_POSIX/pthread.h | 11 ++ .../posix_demo.c | 139 ++++++++++++++++++ .../posix_demo.h | 1 + 5 files changed, 199 insertions(+), 3 deletions(-) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h index d511e69..e296388 100755 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h @@ -46,7 +46,7 @@ #define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the Win32 thread. */ #define configMAX_TASK_NAME_LEN ( 7 ) -#define configUSE_TRACE_FACILITY 0 +#define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_CO_ROUTINES 0 diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c index f34e9ec..317db5a 100755 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c @@ -409,11 +409,19 @@ int pthread_join( pthread_t pthread, int iStatus = 0; pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread; + if (pxThread == NULL) + { + iStatus = ESRCH; + } + /* Make sure pthread is joinable. Otherwise, this function would block * forever waiting for an unjoinable thread. */ - if( !pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) ) + if (iStatus == 0) { - iStatus = EDEADLK; + if( !pthreadIS_JOINABLE(pxThread->xAttr.usSchedPriorityDetachState) ) + { + iStatus = EDEADLK; + } } /* Only one thread may attempt to join another. Lock the join mutex @@ -473,6 +481,43 @@ int pthread_join( pthread_t pthread, return iStatus; } +/*-----------------------------------------------------------*/ +int pthread_cancel( pthread_t pthread ) +{ + int iStatus = 0; + pthread_internal_t * pxThread = (pthread_internal_t *) pthread; + + if (pxThread == NULL || pxThread->xTaskHandle == NULL) + { + iStatus = ESRCH; + } + + /* Threads may already be successfully ended elsewhere and pending full deletion in idle task. */ + /* Note the the xJoinBarrier is a binary sem, so no new queue items are made once its already given */ + if (iStatus == 0 && eDeleted != eTaskGetState(pxThread->xTaskHandle)) + { + if (pxThread == pthread_self()) + { + prvExitThread(); + } + else + { + if (pthreadIS_JOINABLE(pxThread->xAttr.usSchedPriorityDetachState)) + { + xSemaphoreGive((SemaphoreHandle_t)&pxThread->xJoinBarrier); + vTaskSuspend(pxThread->xTaskHandle); + } + else + { + vTaskDelete(pxThread->xTaskHandle); + vPortFree(pxThread); + } + } + } + + return iStatus; +} + /*-----------------------------------------------------------*/ pthread_t pthread_self( void ) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h index 77f949a..ca503bb 100755 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h @@ -233,6 +233,16 @@ int pthread_barrier_init( pthread_barrier_t * barrier, */ int pthread_barrier_wait( pthread_barrier_t * barrier ); +/** +* @brief Request cancellation of thread. +* +* @see https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html +* +* @retval 0 - Upon successful completion. +* @retval ESRCH - Upon attempt to cancel null thread. +*/ +int pthread_cancel( pthread_t thread ); + /** * @brief Thread creation. * @@ -354,6 +364,7 @@ int pthread_getschedparam( pthread_t thread, * to a joinable thread OR multiple simultaneous calls to pthread_join() * specifying the same target thread OR the value specified by the thread argument * to pthread_join() refers to the calling thread. + * @retval ESRCH - Upon attempt to join null thread. */ int pthread_join( pthread_t thread, void ** retval ); diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c index 63560c7..e2eb3ce 100755 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c @@ -69,6 +69,7 @@ /* FreeRTOS includes. */ #include "FreeRTOS_POSIX.h" +#include "FreeRTOS.h" /* System headers. */ #include @@ -370,5 +371,143 @@ void vStartPOSIXDemo( void *pvParameters ) /* This task was created with the native xTaskCreate() API function, so must not run off the end of its implementing thread. */ + printf("\n------ SUMMARY ------\n"); + static char status[40 * 100] = { 0 }; + vTaskList(status); + printf(status); + printf("\n"); vTaskDelete( NULL ); } + + +/*-----------------------------------------------------------*/ +#define N_DUMMY_THREADS 10 +#define N_DUMMY_LOOPS 100 + +static void * prvDummyThread(void* pvArgs) +{ + int id = (int)pvArgs; + + struct timespec ts = { + .tv_sec = 1, + .tv_nsec = 0 + }; + + for (int i = 0; i < N_DUMMY_LOOPS; i++) + { + printf("Thread[%02d] loop[%02d]\n", id, i); + nanosleep(&ts, NULL); + } + + while (1); + + return 0; +} + +static void * prvSelfDestructThread(void* pvArgs) +{ + struct timespec ts = { + .tv_sec = 1, + .tv_nsec = 0 + }; + + nanosleep(&ts, NULL); + configASSERT(0 == pthread_cancel(pthread_self())); + + ts.tv_sec = 1; + while (1) { + nanosleep(&ts, NULL); + } +} + +/* + * Create various joinable/detached threads and cancel/join them in various orders + */ +void vTestPthreadCancel(void* pvParameters) +{ + pthread_attr_t pattr; + struct sched_param sched_config; + pthread_t threads[N_DUMMY_THREADS] = { 0 }; + pthread_attr_init(&pattr); + + /* Want these tasks of equal priority so they can preempt eachother. The spawner task (THIS) will + exhaustively cancel all the threads with pthread_cancel */ + sched_config.sched_priority = uxTaskPriorityGet(NULL); + pthread_attr_setschedparam(&pattr, &sched_config); + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); + + + printf("Creating %d threads looping %d times\n", N_DUMMY_THREADS, N_DUMMY_LOOPS); + /* The first half is default (joinable) the second half is detached*/ + for (int i = 0; i < N_DUMMY_THREADS; i++) + { + if (i == (N_DUMMY_THREADS / 2)) + { + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); + } + + pthread_create(&threads[i], &pattr, prvDummyThread, (void *)i); + } + + struct timespec ts = { + .tv_sec = 1, + .tv_nsec = 0 + }; + + /*Let the test threads run for a bit, then exercise typical cancellation*/ + for (int i=0; i < N_DUMMY_THREADS; i++) + { + nanosleep(&ts, NULL); + + if (i < (N_DUMMY_THREADS / 2)) + { + /* A cancelled joinable thread won't have relinquished its resources, but instead will suspend to joining */ + configASSERT(0 == pthread_cancel(threads[i])); + configASSERT(0 == pthread_join(threads[i], NULL)); + } + else + { + /* A detached thread will fully relinquish resources its responsible for */ + configASSERT(0 == pthread_cancel(threads[i])); + } + } + + /* Excercise cancelling a NULL thread */ + configASSERT(ESRCH == pthread_cancel(NULL)); + + /* Exercise a thread cancelling itself using pthread_cancel */ + pthread_t self_desctructor = NULL; + /* detached thread */ + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); + pthread_create(&self_desctructor, &pattr, prvSelfDestructThread, NULL); + /* joinable thread */ + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); + pthread_create(&self_desctructor, &pattr, prvSelfDestructThread, NULL); + configASSERT(0 == pthread_join(self_desctructor, NULL)); + + /* Excercise double cancellation of: */ + pthread_t doubly_cancelled = NULL; + /* detached thread */ + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); + pthread_create(&doubly_cancelled, &pattr, prvDummyThread, NULL); + pthread_cancel(doubly_cancelled); + pthread_cancel(doubly_cancelled); + + /* joinable thread */ + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); + pthread_create(&doubly_cancelled, &pattr, prvDummyThread, NULL); + pthread_cancel(doubly_cancelled); + pthread_cancel(doubly_cancelled); + configASSERT(0 == pthread_join(doubly_cancelled, NULL)); + + /* All threads should be cancelled by now, leaving only this, main, idle, and timer tasks*/ + printf("\n------ SUMMARY ------\n"); + nanosleep(&ts, NULL); + static char status[40 * (N_DUMMY_THREADS + 5 + 3)] = { 0 }; + vTaskList(status); + printf(status); + printf("\n"); + vTaskDelete(NULL); +} + + diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h index 2088803..dcadf6e 100755 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h @@ -28,5 +28,6 @@ #ifndef _POSIX_DEMO_H_ #define _POSIX_DEMO_H_ void vStartPOSIXDemo( void * pvParameters ); +void vTestPthreadCancel(void* pvParameters); #endif /* _POSIX_DEMO_H_ */ \ No newline at end of file From 3c90157d3792de01e275d0d0d16fad5fbb3e5873 Mon Sep 17 00:00:00 2001 From: David Chalco Date: Fri, 21 Feb 2020 11:18:34 -0800 Subject: [PATCH 2/7] uncrustify --- .../FreeRTOSConfig.h | 93 +++++------ .../source/FreeRTOS_POSIX_pthread.c | 28 ++-- .../lib/include/FreeRTOS_POSIX/pthread.h | 14 +- .../posix_demo.c | 155 +++++++++--------- .../posix_demo.h | 4 +- 5 files changed, 151 insertions(+), 143 deletions(-) mode change 100755 => 100644 FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h mode change 100755 => 100644 FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c mode change 100755 => 100644 FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h mode change 100755 => 100644 FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c mode change 100755 => 100644 FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h old mode 100755 new mode 100644 index e296388..4360e9f --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOSConfig.h @@ -32,50 +32,50 @@ #include /*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. - * http://www.freertos.org/a00110.html - *----------------------------------------------------------*/ - -#define configUSE_PREEMPTION 1 -#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ -#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the Win32 thread. */ -#define configMAX_TASK_NAME_LEN ( 7 ) -#define configUSE_TRACE_FACILITY 1 -#define configUSE_16_BIT_TICKS 0 -#define configIDLE_SHOULD_YIELD 1 -#define configUSE_CO_ROUTINES 0 -#define configUSE_MUTEXES 1 -#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */ -#define configUSE_RECURSIVE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 0 -#define configUSE_APPLICATION_TASK_TAG 1 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configUSE_ALTERNATIVE_API 0 - -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY 2 -#define configTIMER_QUEUE_LENGTH 20 -#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) - -#define configMAX_PRIORITIES ( 7 ) -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +* Application specific definitions. +* +* These definitions should be adjusted for your particular hardware and +* application requirements. +* +* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE +* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. +* http://www.freertos.org/a00110.html +*----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the Win32 thread. */ +#define configMAX_TASK_NAME_LEN ( 7 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_CO_ROUTINES 0 +#define configUSE_MUTEXES 1 +#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */ +#define configUSE_RECURSIVE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 0 +#define configUSE_APPLICATION_TASK_TAG 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 0 + +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY 2 +#define configTIMER_QUEUE_LENGTH 20 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +#define configMAX_PRIORITIES ( 7 ) +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Hook functions */ -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 -#define configUSE_MALLOC_FAILED_HOOK 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configUSE_MALLOC_FAILED_HOOK 1 /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 +#define configUSE_CO_ROUTINES 0 /* Set the following definitions to 1 to include the API function, or zero -to exclude the API function. */ + * to exclude the API function. */ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 @@ -95,25 +95,26 @@ to exclude the API function. */ #define INCLUDE_xTaskAbortDelay 1 /* heap_4.c, */ -#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2048U * 1024U ) ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2048U * 1024U ) ) /* Allow RTOS objects to be created using RAM provided by the application writer. */ #define configSUPPORT_STATIC_ALLOCATION 1 /* Create RTOS objects using dynamically allocated RAM */ -#define configSUPPORT_DYNAMIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 /* This demo makes use of one or more example stats formatting functions. These -format the raw data provided by the uxTaskGetSystemState() function in to human -readable ASCII form. See the notes in the implementation of vTaskList() within -FreeRTOS/Source/tasks.c for limitations. */ -#define configUSE_STATS_FORMATTING_FUNCTIONS 1 + * format the raw data provided by the uxTaskGetSystemState() function in to human + * readable ASCII form. See the notes in the implementation of vTaskList() within + * FreeRTOS/Source/tasks.c for limitations. */ +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 /* Run time stats gathering definitions. */ -#define configGENERATE_RUN_TIME_STATS 0 +#define configGENERATE_RUN_TIME_STATS 0 /* Assert call defined for debug builds. */ -extern void vAssertCalled(const char * pcFile, uint32_t ulLine); +extern void vAssertCalled( const char * pcFile, + uint32_t ulLine ); #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ ) #endif /* FREERTOS_CONFIG_H */ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c old mode 100755 new mode 100644 index 317db5a..9809525 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c @@ -409,16 +409,16 @@ int pthread_join( pthread_t pthread, int iStatus = 0; pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread; - if (pxThread == NULL) + if( pxThread == NULL ) { iStatus = ESRCH; } /* Make sure pthread is joinable. Otherwise, this function would block * forever waiting for an unjoinable thread. */ - if (iStatus == 0) + if( iStatus == 0 ) { - if( !pthreadIS_JOINABLE(pxThread->xAttr.usSchedPriorityDetachState) ) + if( !pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) ) { iStatus = EDEADLK; } @@ -485,32 +485,32 @@ int pthread_join( pthread_t pthread, int pthread_cancel( pthread_t pthread ) { int iStatus = 0; - pthread_internal_t * pxThread = (pthread_internal_t *) pthread; - - if (pxThread == NULL || pxThread->xTaskHandle == NULL) + pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread; + + if( ( pxThread == NULL ) || ( pxThread->xTaskHandle == NULL ) ) { iStatus = ESRCH; - } + } /* Threads may already be successfully ended elsewhere and pending full deletion in idle task. */ /* Note the the xJoinBarrier is a binary sem, so no new queue items are made once its already given */ - if (iStatus == 0 && eDeleted != eTaskGetState(pxThread->xTaskHandle)) + if( ( iStatus == 0 ) && ( eDeleted != eTaskGetState( pxThread->xTaskHandle ) ) ) { - if (pxThread == pthread_self()) + if( pxThread == pthread_self() ) { prvExitThread(); } else { - if (pthreadIS_JOINABLE(pxThread->xAttr.usSchedPriorityDetachState)) + if( pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) ) { - xSemaphoreGive((SemaphoreHandle_t)&pxThread->xJoinBarrier); - vTaskSuspend(pxThread->xTaskHandle); + xSemaphoreGive( ( SemaphoreHandle_t ) &pxThread->xJoinBarrier ); + vTaskSuspend( pxThread->xTaskHandle ); } else { - vTaskDelete(pxThread->xTaskHandle); - vPortFree(pxThread); + vTaskDelete( pxThread->xTaskHandle ); + vPortFree( pxThread ); } } } diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h old mode 100755 new mode 100644 index ca503bb..699778e --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/pthread.h @@ -234,13 +234,13 @@ int pthread_barrier_init( pthread_barrier_t * barrier, int pthread_barrier_wait( pthread_barrier_t * barrier ); /** -* @brief Request cancellation of thread. -* -* @see https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html -* -* @retval 0 - Upon successful completion. -* @retval ESRCH - Upon attempt to cancel null thread. -*/ + * @brief Request cancellation of thread. + * + * @see https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html + * + * @retval 0 - Upon successful completion. + * @retval ESRCH - Upon attempt to cancel null thread. + */ int pthread_cancel( pthread_t thread ); /** diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c old mode 100755 new mode 100644 index e2eb3ce..9d032db --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c @@ -272,12 +272,12 @@ static void * prvDispatcherThread( void * pvArgs ) * * See the top of this file for detailed description. */ -void vStartPOSIXDemo( void *pvParameters ) +void vStartPOSIXDemo( void * pvParameters ) { int i = 0; int iStatus = 0; - /* Remove warnings about unused parameters. */ + /* Remove warnings about unused parameters. */ ( void ) pvParameters; /* Handles of the threads and related resources. */ @@ -369,145 +369,152 @@ void vStartPOSIXDemo( void *pvParameters ) printf( "Queues did not get initialized properly. Did not run demo. %s", LINE_BREAK ); } - /* This task was created with the native xTaskCreate() API function, so - must not run off the end of its implementing thread. */ - printf("\n------ SUMMARY ------\n"); - static char status[40 * 100] = { 0 }; - vTaskList(status); - printf(status); - printf("\n"); - vTaskDelete( NULL ); + /* This task was created with the native xTaskCreate() API function, so + * must not run off the end of its implementing thread. */ + printf( "\n------ SUMMARY ------\n" ); + static char status[ 40 * 100 ] = { 0 }; + vTaskList( status ); + printf( status ); + printf( "\n" ); + vTaskDelete( NULL ); } /*-----------------------------------------------------------*/ -#define N_DUMMY_THREADS 10 -#define N_DUMMY_LOOPS 100 +#define N_DUMMY_THREADS 10 +#define N_DUMMY_LOOPS 100 -static void * prvDummyThread(void* pvArgs) +static void * prvDummyThread( void * pvArgs ) { - int id = (int)pvArgs; + int id = ( int ) pvArgs; - struct timespec ts = { - .tv_sec = 1, + struct timespec ts = + { + .tv_sec = 1, .tv_nsec = 0 }; - for (int i = 0; i < N_DUMMY_LOOPS; i++) + for( int i = 0; i < N_DUMMY_LOOPS; i++ ) { - printf("Thread[%02d] loop[%02d]\n", id, i); - nanosleep(&ts, NULL); + printf( "Thread[%02d] loop[%02d]\n", id, i ); + nanosleep( &ts, NULL ); } - while (1); + while( 1 ) + { + } return 0; } -static void * prvSelfDestructThread(void* pvArgs) +static void * prvSelfDestructThread( void * pvArgs ) { - struct timespec ts = { - .tv_sec = 1, + struct timespec ts = + { + .tv_sec = 1, .tv_nsec = 0 }; - nanosleep(&ts, NULL); - configASSERT(0 == pthread_cancel(pthread_self())); + nanosleep( &ts, NULL ); + configASSERT( 0 == pthread_cancel( pthread_self() ) ); ts.tv_sec = 1; - while (1) { - nanosleep(&ts, NULL); + + while( 1 ) + { + nanosleep( &ts, NULL ); } } /* * Create various joinable/detached threads and cancel/join them in various orders */ -void vTestPthreadCancel(void* pvParameters) +void vTestPthreadCancel( void * pvParameters ) { pthread_attr_t pattr; struct sched_param sched_config; - pthread_t threads[N_DUMMY_THREADS] = { 0 }; - pthread_attr_init(&pattr); + pthread_t threads[ N_DUMMY_THREADS ] = { 0 }; + + pthread_attr_init( &pattr ); /* Want these tasks of equal priority so they can preempt eachother. The spawner task (THIS) will - exhaustively cancel all the threads with pthread_cancel */ - sched_config.sched_priority = uxTaskPriorityGet(NULL); - pthread_attr_setschedparam(&pattr, &sched_config); - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); + * exhaustively cancel all the threads with pthread_cancel */ + sched_config.sched_priority = uxTaskPriorityGet( NULL ); + pthread_attr_setschedparam( &pattr, &sched_config ); + pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); - printf("Creating %d threads looping %d times\n", N_DUMMY_THREADS, N_DUMMY_LOOPS); + printf( "Creating %d threads looping %d times\n", N_DUMMY_THREADS, N_DUMMY_LOOPS ); + /* The first half is default (joinable) the second half is detached*/ - for (int i = 0; i < N_DUMMY_THREADS; i++) + for( int i = 0; i < N_DUMMY_THREADS; i++ ) { - if (i == (N_DUMMY_THREADS / 2)) + if( i == ( N_DUMMY_THREADS / 2 ) ) { - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); + pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED ); } - pthread_create(&threads[i], &pattr, prvDummyThread, (void *)i); + pthread_create( &threads[ i ], &pattr, prvDummyThread, ( void * ) i ); } - - struct timespec ts = { - .tv_sec = 1, + + struct timespec ts = + { + .tv_sec = 1, .tv_nsec = 0 }; /*Let the test threads run for a bit, then exercise typical cancellation*/ - for (int i=0; i < N_DUMMY_THREADS; i++) + for( int i = 0; i < N_DUMMY_THREADS; i++ ) { - nanosleep(&ts, NULL); + nanosleep( &ts, NULL ); - if (i < (N_DUMMY_THREADS / 2)) + if( i < ( N_DUMMY_THREADS / 2 ) ) { /* A cancelled joinable thread won't have relinquished its resources, but instead will suspend to joining */ - configASSERT(0 == pthread_cancel(threads[i])); - configASSERT(0 == pthread_join(threads[i], NULL)); + configASSERT( 0 == pthread_cancel( threads[ i ] ) ); + configASSERT( 0 == pthread_join( threads[ i ], NULL ) ); } else { /* A detached thread will fully relinquish resources its responsible for */ - configASSERT(0 == pthread_cancel(threads[i])); + configASSERT( 0 == pthread_cancel( threads[ i ] ) ); } } - + /* Excercise cancelling a NULL thread */ - configASSERT(ESRCH == pthread_cancel(NULL)); + configASSERT( ESRCH == pthread_cancel( NULL ) ); /* Exercise a thread cancelling itself using pthread_cancel */ pthread_t self_desctructor = NULL; /* detached thread */ - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); - pthread_create(&self_desctructor, &pattr, prvSelfDestructThread, NULL); + pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED ); + pthread_create( &self_desctructor, &pattr, prvSelfDestructThread, NULL ); /* joinable thread */ - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); - pthread_create(&self_desctructor, &pattr, prvSelfDestructThread, NULL); - configASSERT(0 == pthread_join(self_desctructor, NULL)); - + pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); + pthread_create( &self_desctructor, &pattr, prvSelfDestructThread, NULL ); + configASSERT( 0 == pthread_join( self_desctructor, NULL ) ); + /* Excercise double cancellation of: */ pthread_t doubly_cancelled = NULL; /* detached thread */ - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); - pthread_create(&doubly_cancelled, &pattr, prvDummyThread, NULL); - pthread_cancel(doubly_cancelled); - pthread_cancel(doubly_cancelled); + pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED ); + pthread_create( &doubly_cancelled, &pattr, prvDummyThread, NULL ); + pthread_cancel( doubly_cancelled ); + pthread_cancel( doubly_cancelled ); /* joinable thread */ - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); - pthread_create(&doubly_cancelled, &pattr, prvDummyThread, NULL); - pthread_cancel(doubly_cancelled); - pthread_cancel(doubly_cancelled); - configASSERT(0 == pthread_join(doubly_cancelled, NULL)); + pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); + pthread_create( &doubly_cancelled, &pattr, prvDummyThread, NULL ); + pthread_cancel( doubly_cancelled ); + pthread_cancel( doubly_cancelled ); + configASSERT( 0 == pthread_join( doubly_cancelled, NULL ) ); /* All threads should be cancelled by now, leaving only this, main, idle, and timer tasks*/ - printf("\n------ SUMMARY ------\n"); - nanosleep(&ts, NULL); - static char status[40 * (N_DUMMY_THREADS + 5 + 3)] = { 0 }; - vTaskList(status); - printf(status); - printf("\n"); - vTaskDelete(NULL); + printf( "\n------ SUMMARY ------\n" ); + nanosleep( &ts, NULL ); + static char status[ 40 * ( N_DUMMY_THREADS + 5 + 3 ) ] = { 0 }; + vTaskList( status ); + printf( status ); + printf( "\n" ); + vTaskDelete( NULL ); } - - diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h old mode 100755 new mode 100644 index dcadf6e..3e33496 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h @@ -28,6 +28,6 @@ #ifndef _POSIX_DEMO_H_ #define _POSIX_DEMO_H_ void vStartPOSIXDemo( void * pvParameters ); -void vTestPthreadCancel(void* pvParameters); +void vTestPthreadCancel( void * pvParameters ); -#endif /* _POSIX_DEMO_H_ */ \ No newline at end of file +#endif /* _POSIX_DEMO_H_ */ From 9cdb9329dfb67020f821c00ba0a21a0feb2762b9 Mon Sep 17 00:00:00 2001 From: David Chalco Date: Fri, 21 Feb 2020 19:21:43 +0000 Subject: [PATCH 3/7] Undo modification of worker demo thread --- .../posix_demo.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c index 9d032db..3d7b039 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c @@ -371,11 +371,6 @@ void vStartPOSIXDemo( void * pvParameters ) /* This task was created with the native xTaskCreate() API function, so * must not run off the end of its implementing thread. */ - printf( "\n------ SUMMARY ------\n" ); - static char status[ 40 * 100 ] = { 0 }; - vTaskList( status ); - printf( status ); - printf( "\n" ); vTaskDelete( NULL ); } From c8fd2101750326f86d615aab3af93d752e4547e8 Mon Sep 17 00:00:00 2001 From: David Chalco Date: Fri, 21 Feb 2020 19:29:00 +0000 Subject: [PATCH 4/7] Enhance status messages --- .../posix_demo.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c index 3d7b039..b22ad35 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c @@ -438,9 +438,7 @@ void vTestPthreadCancel( void * pvParameters ) pthread_attr_setschedparam( &pattr, &sched_config ); pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); - - printf( "Creating %d threads looping %d times\n", N_DUMMY_THREADS, N_DUMMY_LOOPS ); - + printf( "\nCreating then deleting various threads...\n" ); /* The first half is default (joinable) the second half is detached*/ for( int i = 0; i < N_DUMMY_THREADS; i++ ) { @@ -505,6 +503,7 @@ void vTestPthreadCancel( void * pvParameters ) configASSERT( 0 == pthread_join( doubly_cancelled, NULL ) ); /* All threads should be cancelled by now, leaving only this, main, idle, and timer tasks*/ + printf( "Done.\n" ); printf( "\n------ SUMMARY ------\n" ); nanosleep( &ts, NULL ); static char status[ 40 * ( N_DUMMY_THREADS + 5 + 3 ) ] = { 0 }; From d33a7be2932c455ae8c0ccb6ee56d06fe9c13039 Mon Sep 17 00:00:00 2001 From: David Chalco Date: Fri, 21 Feb 2020 11:30:20 -0800 Subject: [PATCH 5/7] uncrustify --- .../posix_demo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c index b22ad35..598c167 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c @@ -439,6 +439,7 @@ void vTestPthreadCancel( void * pvParameters ) pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); printf( "\nCreating then deleting various threads...\n" ); + /* The first half is default (joinable) the second half is detached*/ for( int i = 0; i < N_DUMMY_THREADS; i++ ) { From 9dee3ce69a033202ba141f6af35dbbeea3cf983c Mon Sep 17 00:00:00 2001 From: David Chalco Date: Sat, 22 Feb 2020 00:04:10 +0000 Subject: [PATCH 6/7] Remove ESRCH and test code --- .../source/FreeRTOS_POSIX_pthread.c | 19 +-- .../posix_demo.c | 142 +----------------- .../posix_demo.h | 2 +- 3 files changed, 5 insertions(+), 158 deletions(-) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c index 9809525..9000336 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c @@ -409,19 +409,11 @@ int pthread_join( pthread_t pthread, int iStatus = 0; pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread; - if( pxThread == NULL ) - { - iStatus = ESRCH; - } - /* Make sure pthread is joinable. Otherwise, this function would block * forever waiting for an unjoinable thread. */ - if( iStatus == 0 ) + if( !pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) ) { - if( !pthreadIS_JOINABLE( pxThread->xAttr.usSchedPriorityDetachState ) ) - { - iStatus = EDEADLK; - } + iStatus = EDEADLK; } /* Only one thread may attempt to join another. Lock the join mutex @@ -487,14 +479,9 @@ int pthread_cancel( pthread_t pthread ) int iStatus = 0; pthread_internal_t * pxThread = ( pthread_internal_t * ) pthread; - if( ( pxThread == NULL ) || ( pxThread->xTaskHandle == NULL ) ) - { - iStatus = ESRCH; - } - /* Threads may already be successfully ended elsewhere and pending full deletion in idle task. */ /* Note the the xJoinBarrier is a binary sem, so no new queue items are made once its already given */ - if( ( iStatus == 0 ) && ( eDeleted != eTaskGetState( pxThread->xTaskHandle ) ) ) + if( pxThread && pxThread->xTaskHandle && ( eDeleted != eTaskGetState( pxThread->xTaskHandle ) ) ) { if( pxThread == pthread_self() ) { diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c index 598c167..b31cedb 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.c @@ -372,144 +372,4 @@ void vStartPOSIXDemo( void * pvParameters ) /* This task was created with the native xTaskCreate() API function, so * must not run off the end of its implementing thread. */ vTaskDelete( NULL ); -} - - -/*-----------------------------------------------------------*/ -#define N_DUMMY_THREADS 10 -#define N_DUMMY_LOOPS 100 - -static void * prvDummyThread( void * pvArgs ) -{ - int id = ( int ) pvArgs; - - struct timespec ts = - { - .tv_sec = 1, - .tv_nsec = 0 - }; - - for( int i = 0; i < N_DUMMY_LOOPS; i++ ) - { - printf( "Thread[%02d] loop[%02d]\n", id, i ); - nanosleep( &ts, NULL ); - } - - while( 1 ) - { - } - - return 0; -} - -static void * prvSelfDestructThread( void * pvArgs ) -{ - struct timespec ts = - { - .tv_sec = 1, - .tv_nsec = 0 - }; - - nanosleep( &ts, NULL ); - configASSERT( 0 == pthread_cancel( pthread_self() ) ); - - ts.tv_sec = 1; - - while( 1 ) - { - nanosleep( &ts, NULL ); - } -} - -/* - * Create various joinable/detached threads and cancel/join them in various orders - */ -void vTestPthreadCancel( void * pvParameters ) -{ - pthread_attr_t pattr; - struct sched_param sched_config; - pthread_t threads[ N_DUMMY_THREADS ] = { 0 }; - - pthread_attr_init( &pattr ); - - /* Want these tasks of equal priority so they can preempt eachother. The spawner task (THIS) will - * exhaustively cancel all the threads with pthread_cancel */ - sched_config.sched_priority = uxTaskPriorityGet( NULL ); - pthread_attr_setschedparam( &pattr, &sched_config ); - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); - - printf( "\nCreating then deleting various threads...\n" ); - - /* The first half is default (joinable) the second half is detached*/ - for( int i = 0; i < N_DUMMY_THREADS; i++ ) - { - if( i == ( N_DUMMY_THREADS / 2 ) ) - { - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED ); - } - - pthread_create( &threads[ i ], &pattr, prvDummyThread, ( void * ) i ); - } - - struct timespec ts = - { - .tv_sec = 1, - .tv_nsec = 0 - }; - - /*Let the test threads run for a bit, then exercise typical cancellation*/ - for( int i = 0; i < N_DUMMY_THREADS; i++ ) - { - nanosleep( &ts, NULL ); - - if( i < ( N_DUMMY_THREADS / 2 ) ) - { - /* A cancelled joinable thread won't have relinquished its resources, but instead will suspend to joining */ - configASSERT( 0 == pthread_cancel( threads[ i ] ) ); - configASSERT( 0 == pthread_join( threads[ i ], NULL ) ); - } - else - { - /* A detached thread will fully relinquish resources its responsible for */ - configASSERT( 0 == pthread_cancel( threads[ i ] ) ); - } - } - - /* Excercise cancelling a NULL thread */ - configASSERT( ESRCH == pthread_cancel( NULL ) ); - - /* Exercise a thread cancelling itself using pthread_cancel */ - pthread_t self_desctructor = NULL; - /* detached thread */ - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED ); - pthread_create( &self_desctructor, &pattr, prvSelfDestructThread, NULL ); - /* joinable thread */ - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); - pthread_create( &self_desctructor, &pattr, prvSelfDestructThread, NULL ); - configASSERT( 0 == pthread_join( self_desctructor, NULL ) ); - - /* Excercise double cancellation of: */ - pthread_t doubly_cancelled = NULL; - /* detached thread */ - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED ); - pthread_create( &doubly_cancelled, &pattr, prvDummyThread, NULL ); - pthread_cancel( doubly_cancelled ); - pthread_cancel( doubly_cancelled ); - - /* joinable thread */ - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_JOINABLE ); - pthread_create( &doubly_cancelled, &pattr, prvDummyThread, NULL ); - pthread_cancel( doubly_cancelled ); - pthread_cancel( doubly_cancelled ); - configASSERT( 0 == pthread_join( doubly_cancelled, NULL ) ); - - /* All threads should be cancelled by now, leaving only this, main, idle, and timer tasks*/ - printf( "Done.\n" ); - printf( "\n------ SUMMARY ------\n" ); - nanosleep( &ts, NULL ); - static char status[ 40 * ( N_DUMMY_THREADS + 5 + 3 ) ] = { 0 }; - vTaskList( status ); - printf( status ); - printf( "\n" ); - vTaskDelete( NULL ); -} +} \ No newline at end of file diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h index 3e33496..fb5fa8b 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/posix_demo.h @@ -27,7 +27,7 @@ #ifndef _POSIX_DEMO_H_ #define _POSIX_DEMO_H_ + void vStartPOSIXDemo( void * pvParameters ); -void vTestPthreadCancel( void * pvParameters ); #endif /* _POSIX_DEMO_H_ */ From 6b1d9fb21342d176935bc8630439d628043a9c43 Mon Sep 17 00:00:00 2001 From: David Chalco Date: Fri, 21 Feb 2020 17:06:48 -0800 Subject: [PATCH 7/7] Doc line on ESRCH no longer valid. Remove it --- include/FreeRTOS_POSIX/pthread.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/FreeRTOS_POSIX/pthread.h b/include/FreeRTOS_POSIX/pthread.h index 699778e..0e1a0eb 100644 --- a/include/FreeRTOS_POSIX/pthread.h +++ b/include/FreeRTOS_POSIX/pthread.h @@ -239,7 +239,6 @@ int pthread_barrier_wait( pthread_barrier_t * barrier ); * @see https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html * * @retval 0 - Upon successful completion. - * @retval ESRCH - Upon attempt to cancel null thread. */ int pthread_cancel( pthread_t thread ); @@ -364,7 +363,6 @@ int pthread_getschedparam( pthread_t thread, * to a joinable thread OR multiple simultaneous calls to pthread_join() * specifying the same target thread OR the value specified by the thread argument * to pthread_join() refers to the calling thread. - * @retval ESRCH - Upon attempt to join null thread. */ int pthread_join( pthread_t thread, void ** retval );