diff --git a/rtos/include/rtos/Thread.h b/rtos/include/rtos/Thread.h index 1aa72de..2083e32 100644 --- a/rtos/include/rtos/Thread.h +++ b/rtos/include/rtos/Thread.h @@ -131,7 +131,8 @@ /** Starts a thread executing the specified function. @param task function to be executed by this thread. - @return status code that indicates the execution status of the function. + @return status code that indicates the execution status of the function, + or osErrorNoMemory if stack allocation failed. @note a thread can only be started once @note You cannot call this function ISR context. diff --git a/rtos/source/Thread.cpp b/rtos/source/Thread.cpp index 8d1fa92..3b9a8d9 100644 --- a/rtos/source/Thread.cpp +++ b/rtos/source/Thread.cpp @@ -81,8 +81,11 @@ } if (_attr.stack_mem == nullptr) { - _attr.stack_mem = new uint32_t[_attr.stack_size / sizeof(uint32_t)]; - MBED_ASSERT(_attr.stack_mem != nullptr); + _attr.stack_mem = new (std::nothrow) uint32_t[_attr.stack_size / sizeof(uint32_t)]; + if (_attr.stack_mem == nullptr) { + _mutex.unlock(); + return osErrorNoMemory; + } } //Fill the stack with a magic word for maximum usage checking