diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 013c4898319..580502cc03c 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -167,13 +167,15 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, thread->pvParams = pvParameters; thread->xDying = pdFALSE; + /* Ensure ulStackSize is at least PTHREAD_STACK_MIN */ + ulStackSize = (ulStackSize < PTHREAD_STACK_MIN) ? PTHREAD_STACK_MIN : ulStackSize; + pthread_attr_init( &xThreadAttributes ); - iRet = pthread_attr_setstack( &xThreadAttributes, pxEndOfStack, ulStackSize ); + iRet = pthread_attr_setstacksize( &xThreadAttributes, ulStackSize ); if( iRet != 0 ) { - fprintf( stderr, "[WARN] pthread_attr_setstack failed with return value: %d. Default stack will be used.\n", iRet ); - fprintf( stderr, "[WARN] Increase the stack size to PTHREAD_STACK_MIN.\n" ); + fprintf( stderr, "[WARN] pthread_attr_setstacksize failed with return value: %d. Default stack size will be used.\n", iRet ); } thread->ev = event_create();