I want to dispatch two different eventqueue on two threads so that I can modify their priorities. They should toggle two led at different frequencies. However, only one of them would turn on. It seems that the OS never switches task even if I use ThisThread::yield(); . What am I missing here? Thanks in advance.
just try cutout queueX.dispatch_forever(); from your code, because you already do it in thread.start(...) and also you need to add while(1); to the end of main.
The LEDs wouldn’t turn on if I get rid of the dispatch_forever(); after calling queueX.call_every(); I tried to to modify it to the following code and lights are flashing but if change both queue1 and queue 2 to dispatch_once(); neither of the LEDs will turn on. I am not sure why.
Why do I need a while(1) inside of my main? Thank you!
Why do I need a while(1) inside of my main? Thank you!
Without that the main thread is terminated and goes out the scope. This results in deleting of all the variables declared/defined in it’s scope (i.e. t1, t2, queue1 and queue2).
If you declare/define them as global then the program should work without having an endless while loop inside the main function: