[En-Nut-Discussion] NutEventPost Handling

Harald Kipp harald.kipp at egnite.de
Mon Jul 19 18:53:06 CEST 2004


Matthias,

you're right. NutThreadAddPriQueue() inserts a thread behind
any other with same or higher priority. Thus, the woken up
thread is inserted behind the posting thread, if both do
have the same priority.

This way, NutYield() will remove a thread from the run-queue
and re-insert it behind threads with higher or equal priority.


At 17:48 19.07.2004 +0200, you wrote:

>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 ?

I agree with your view. The code above could be easily fixed
by adding NutThreadYield(), but it makes more sense to me too,
if NetEventPost() does this internally. Looks more consistent,
IMHO.

Harald

P.S. Your sample will switch the context, because sooner or later
printf() will put the thread to sleep. But I got your point.




More information about the En-Nut-Discussion mailing list