Shedular/Thread issue

Hi Guys,

I am having a problem with the test code below. Only one thread seems to run even though I give a thread_yield() to it periodically … even the loop in main is ignored.

Is there some issue with the shedular I am not aware of? I thought that the LED thread would get some action? Especially as it has higher priority than the pulser thread.

Cheers,

Bernie

Hello Bernard,

our thread priorities are "reversed". The lowest number has the highest priority. PRIORITY_MAIN is medium priority, 0 is the highest priority level, and PRIORITY_IDLE-1 is the least priority.

I hope this helps,

Hi Reme,

I understand that. That is why the LED thread has the highest priority (-3) and the Pulser thread the lowest …

Still don’t understand why it does not work.

Bernie

Hi Bernie,

Try creating the first thread with the CREATE_WOUT_YIELD flag.

It's too early for me to decide whether this indicates an issue with the scheduler.

Cheers, Ludwig

Hi Bernie,

I am having a problem with the test code below. Only one thread seems to run even though I give a thread_yield() to it periodically .. even the loop in main is ignored.

Is there some issue with the shedular I am not aware of? I thought that the LED thread would get some action? Especially as it has higher priority than the pulser thread.

if I don't miss anything I would say, everything's okay.

The main thread starts the pulser thread which immediately takes over (higher priority, not create with CREATE_WOUT_YIELD). Thread pulser runs and yields. Now the scheduler checks which thread is ready to run and has the highest priority -> since led hasn't been created and main has a lower priority, pulser is scheduled again. And so on.

As Ludwig suggested, you probably want to create pulser with the CREATE_WOUT_YIELD flag. If you want a thread to yield and removed from the run queue, you'll have to use thread_sleep().

Cheers, Oleg

Ho Oleg,

I am still totally confused! I did as you stated, but my “pulser” thread is not entered … the LED thread runs flashing the LED. code below …

I am about to give up!

Bernie.

Hi Bernie,

To combine the flags, you need to use the logic operator |.

Cheers, Ludwig

Actually Ludwig, it does not matter if you use “|” or “+” it achieve the same thing …

Bernie

I tried your example application yesterday and it worked for me, I only changed this one thing.

Cheers.

Hi Bernie!

I am still totally confused! I did as you stated, but my "pulser" thread is not entered ... the LED thread runs flashing the LED. code below ..

I am about to give up!

Don't give up! It's not that complicated and once you've figured out how the scheduler works, it's quite easy to work with.

I guess my explanation was a little bit confusing. I meant that you should only add the CREATE_WOUT_YIELD flag to thread_create() - _not_ additionally replace thread_yield() with thread_sleep().

If you use thread_sleep() you'll also have to wake the thread up somewhere.

So, as Ludwig stated: just adding CREATE_WOUT_YIELD should be fine. (Works as expected in native.)

Cheers, Oleg