mbed-os/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
..
include/rtos rtos: Thread: Make stack allocation failure runtime catchable 2021-09-08 14:17:58 +01:00
source rtos: Thread: Make stack allocation failure runtime catchable 2021-09-08 14:17:58 +01:00
tests Merge pull request #15045 from LDong-Arm/malloc_newlib_nano 2021-09-03 15:03:31 +01:00
CMakeLists.txt Update rtos CMake to include greentea test dir 2021-08-23 21:44:36 +01:00
LICENSE-mit.txt rtos: add license information 2019-04-16 11:26:39 +01:00
LICENSE.md Remove RtosTimer deprecated class and its APIs 2020-03-09 09:52:29 -07:00
mbed_lib.json RTOS API for bare metal 2019-07-15 10:13:50 +03:00