Transient threads: How to release allocated memory automatically?
Posted: Thu Jan 18, 2018 3:40 am
In the docs, it's clearly stated that `chThdCreateFromHeap()` does not release the allocated memory to the heap but it's a mandatory action if I don't design the application in a wrong way.
There is a `blink()` function that receives a message, turns an output on, waits a little bit and then turns that output off. Every message should be handled in parallel. If I create a static thread per message, it works correctly for only one output. If multiple messages arrive back-to-back for multiple outputs, 3-4 outputs are turned on and MCU freezes.
It experiences a stack overflow since I don't release any of the threads I created. Why should I manually call the `chThdWait()` function as it is blocking (so there seems no point using a thread if I would block the execution?).
The other (and more important) question is, how can I release the allocated memory as soon as the dynamic thread exits?
There is a `blink()` function that receives a message, turns an output on, waits a little bit and then turns that output off. Every message should be handled in parallel. If I create a static thread per message, it works correctly for only one output. If multiple messages arrive back-to-back for multiple outputs, 3-4 outputs are turned on and MCU freezes.
It experiences a stack overflow since I don't release any of the threads I created. Why should I manually call the `chThdWait()` function as it is blocking (so there seems no point using a thread if I would block the execution?).
The other (and more important) question is, how can I release the allocated memory as soon as the dynamic thread exits?