I found the problem and checked for a fix in the latest version of nil. It appears it would have the same problem.
At line 680 of ch.c, trunk 10022, the wrong value is returned.
Code: Select all
if (NIL_THD_IS_READY(ntp)) {
nil.current = nil.next = ntp;
if (ntp == &nil.threads[CH_CFG_NUM_THREADS]) {
CH_CFG_IDLE_ENTER_HOOK();
}
port_switch(ntp, otp);
return nil.current->u1.msg; <<------------ Line 680.
}
If I replace the return with this it is correct.
Code: Select all
return otp->u1.msg;
Also it works if I make the the "current" member of nil_system_t volatile.
What is the best fix?