[En-Nut-Discussion] NutEventPost Handling

Matthias Ringwald mringwal at inf.ethz.ch
Mon Jul 19 17:48:38 CEST 2004


hi there

while debugging, besides own faults, I found an inconsistency in nut/os 
(CVS head) event handling.

NutEventPost docu says:
  * Wake up the thread with the highest priority waiting on this queue.
  * If the priority of the waiting thread is higher or equal than the
  * current thread's priority, then the current thread is stopped and
  * CPU control is passed to the waiting thread.
  *

and it calls NutEventPostAsync and checks if the runQueue changed

NutEventPostAsync calls NutThreadResumeAsync, which calls 
NutThreadAddPriQueue
whose docu says:
  * Insert the thread into a specified queue behind
  * the last thread with lower or equal priority.

so. if the current thread and the thread to wake have the same priority,
then the thread to wake will be inserted BEHIND the current thread into
the run queue hence no thread switch will appear.


options: fix the behavior of NutEventPost to match the docu
or match the docu to the behaviour.

I'd prefer fixing the code.
// simple fix: replace if (runningThread..) { ... } with 
NutThreadYield()

Example: I have two threads T1, T2. Both are using the same resource 
like an uart.
Then I have to lock the UART using something like

f {
	NutEventWait()
	printf()...
	NutEventPost()
}

T1: for (;;) f;
T2: for (;;) f;

With the current implementation, T2 will never get the UART..

other comments on this ?


matthias







More information about the En-Nut-Discussion mailing list