Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 3 months ago.
Thread.start(func) error -4
I have started a thread using mbed 5.5.6 and let it run to completion. ex: Thread myThread; osStatus stat=myThread.start(func);
by printing stat it equals 0 - thread started correctly.
func runs to completion. I then restart it
osStatus stat=myThread.start(func);
the thread never restarts and stat=-4, -4 is not defined as an error code in cmsis_os.h so I have no idea what has happened.
1 Answer
7 years, 3 months ago.
At the moment, restarting a completed thread this way is unsupported. Threads are required in embedded systems to be both lightweight and simple. Your best bet is to create a new thread or use placement new
Your answer is surprising as object creation is usually not a lightweight operation. In addition this method worked in previous versions of MBED OS. It would seem that restarting a thread this way is no heavier than starting it in the first place. IMHO this is a bug. I have worked around this by putting the thread in a while(true) loop with a wait on signal at the end to restart it. Although less than satisfying it does work.
posted by 21 Sep 2017
Please post your full code in "
posted by Mark Peter Vargha 10 Sep 2017<<code>>
" block.The code is too large to post here, I have a work around now but if you are interested in solving the issue I suggest you try to create a small code snippit and try it.
posted by Dan Sexton 11 Sep 2017try this: