[En-Nut-Discussion] Unexpected thread switching

Ole Reinhardt ole.reinhardt at embedded-it.de
Tue Jan 22 12:33:24 CET 2013


Hi Markus,

> I run an application on the EIR and Nut/OS 4.10.3 with four threads: 
> idle, main, ethernet and a webserver. But when I use the functions 
> "fprintf" in the main-thread or "NutHttpProcessPostQuery" in the 
> webserver-thread, it happened, that a unexpected thread switch is 
> executed. I don't use any functions for thread switching in this 
> context. Can anyone explain to me, how this can happen?

Not only functions like "NutThreadYield()", "NutSleep()" and
"NutEventWait()" will cause a thread switch, but also other functions
that internally might wait for some events.

In other words:

fprintf() will call the "write()" function of the UART driver, which
works interrupt driven. And as the driver code will wait for an
interrupt before proceeding, it calls NutEventWait() on an event queue
that will later be signalled by the UART interrupt.

Finally this influences the fprintf() call as well.

There are lots of functions that call internal driver routines that
might result in thread switches as well.

Best regards,

Ole Reinhardt



More information about the En-Nut-Discussion mailing list