mbed-os/rtos/include/rtos
Lingkai Dong 48cf1c9c80 rtos: Thread: Make stack allocation failure runtime catchable
When a Thread object's stack memory is not provided, its `start()`
member function dynamically allocates its stack from the heap. If
allocation fails, there is no way to catch it because
* `std::nothrow` is missing after the `new` keyword. As Mbed OS
is built with `-fno-exceptions` (C++ exceptions disabled), failed
allocation results in an unrecoverable fault.
* The attempted `nullptr` check, which doesn't work anyway due to
the first point, is an assertion instead of error returning.
Assertions should be used as a development tool to ensure code
behaves correctly. But out-of-memory is a completely valid runtime
situation.

This commit adds the missing `std::nothrow`, and makes `Thread::start()`
return `osErrorNoMemory` if allocation fails so the caller can handle
it.

Note: A case when a thread should never fail due to lack of memory
is the main thread. But the main thread's stack is a pre-allocated
array in the static memory, passed to the `Thread()` constructor
during thread creation, so it's not impacted by this change.
2021-09-08 14:17:58 +01:00
..
internal rtos: Remove UNITTEST macro from rtos 2021-07-06 16:50:49 +01:00
ConditionVariable.h Incorporating reveiw comments - Moving mbed_rtos_types.h to public headers 2020-07-15 13:54:52 +01:00
EventFlags.h Incorporating reveiw comments - Moving mbed_rtos_types.h to public headers 2020-07-15 13:54:52 +01:00
Kernel.h platform: move internal headers to internal/ 2020-08-20 08:58:00 +01:00
Mail.h Incorporating reveiw comments - Moving mbed_rtos_types.h to public headers 2020-07-15 13:54:52 +01:00
MemoryPool.h Better document MemoryPool behaviour 2021-04-13 14:37:47 +03:00
Mutex.h Fixed doxygen comment 2020-07-20 17:40:41 +01:00
Queue.h Include mbed_assert.h in Queue 2020-07-30 11:23:24 -04:00
Semaphore.h Fixed doxygen comment 2020-07-20 17:40:41 +01:00
ThisThread.h Incorporating reveiw comments - Moving mbed_rtos_types.h to public headers 2020-07-15 13:54:52 +01:00
Thread.h rtos: Thread: Make stack allocation failure runtime catchable 2021-09-08 14:17:58 +01:00
mbed_rtos_types.h rtos: Remove UNITTEST macro from rtos 2021-07-06 16:50:49 +01:00
rtos.h Moving around a few items within \rtos 2020-07-09 15:57:29 +01:00