PikoRT / pikoRT

A tiny Linux-like real-time kernel optimized for ARM Cortex-M chips
Other
303 stars 61 forks source link

Idle thread problem in bitmap scheduler #55

Closed kaizsv closed 6 years ago

kaizsv commented 6 years ago

https://github.com/PikoRT/pikoRT/blob/d68fe3d070a23910b9304cca52b8c8b77c075304/kernel/sched/bitmap.c#L102

Hello

I'm confused at this part. If both runqueues are empty, the bitmap scheduler will select idle as next thread. But this condition statement causes current thread not to switch to idle thread and returns directly. I replace this line as follows. In cond_2 test case, the gdb will stop at the second line but the 'do_idle' function never been executed. Is there any reason not to perform context switch while next thread is idle?

if (next == current) return 0; if (next == thread_idle) return 0;

jserv commented 6 years ago

Exactly, it was a logic error. Can you send a pull request to revise the sequence of checking current and idle thread with corresponding explanation?