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.
8 years, 6 months ago.
How thread are managed in this simple example
Hi,
I'm looking to lean how Thread in mbed works and I have a little problem.
With this piece of code, everything works well as it is similar to the Thread wiki page example: http://pastebin.com/QMmtrptN
But if I want to include the second blinker (the one for the yellow led) in a Thread too, and have one thread for my red led, one for my yellow led, and the main thread, it does not works: http://pastebin.com/7Ksr6BgJ In the second case, none of both led blinks.
Do you have any informations about why and how can I fix this ?
Thanks.
1 Answer
8 years, 6 months ago.
In the second case the program exits as soon as it has set up the threads. The program has finished, it's not going to change the LEDs after that point.
Try this:
int main(void) { Thread red_led(blink_red_led); Thread yellow_led(blink_yellow_led); while (true) { Thread::wait(10000); } return 0; }
I supposed that while a thread is alive the main thread still live. But ok good news !
So that was the easy case; Now here is my "real" problem: http://forums.mbed.com/t/thread-and-serial-interrupt-with-queue/1523 If you have a minut to see and maybe help me ? Thanks.
posted by 12 May 2016Sorry, no idea. I've not used the mbed OS. You have the same issue there of the main thread exiting almost as soon as the program starts but I assume that you've now tried changing that and it didn't fix things.
Is this a learning exercise or are you planning on adding a network server or similar later because an OS is overkill for if all you need to do is display serial data on a screen.
posted by 12 May 2016