mbed-os/rtos/source
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
..
ConditionVariable.cpp Add Chrono and predicate support to ConditionVariable 2020-04-27 10:19:08 +03:00
EventFlags.cpp platform: move internal headers to internal/ 2020-08-20 08:58:00 +01:00
Kernel.cpp platform: move internal headers to internal/ 2020-08-20 08:58:00 +01:00
Mutex.cpp Mutex::unlock - decrement _count inside lock 2020-05-15 19:10:53 +03:00
Semaphore.cpp platform: move internal headers to internal/ 2020-08-20 08:58:00 +01:00
ThisThread.cpp rtos: fix delay with 0 2021-07-29 14:31:39 +01:00
Thread.cpp rtos: Thread: Make stack allocation failure runtime catchable 2021-09-08 14:17:58 +01:00
rtos_handlers.h rtos: fix SPDX identifiers 2020-02-21 07:00:57 +00:00
rtos_idle.h rtos: fix SPDX identifiers 2020-02-21 07:00:57 +00:00