[En-Nut-Discussion] NutThreadSetPriority

Yuri Staal staal.ya at stu.hsbrabant.nl
Fri Dec 5 12:13:51 CET 2003


i am now outputting almost everything that is done to HYperTerminal.
i have seen a lot of stuff that isnt supposed to happen the way i think
it should happen.
for instance:

for (i = 0; i < 4; i++) {
       char *thname = "main";
       thname[4] = '0' + i;
       NutThreadCreate(thname, NutMain, (void *) (u_short) i, 640);
       printf("[%i] Name: %s\r\n", i, tdp->td_name);
       }
NutThreadSetPriority(255);
printf("[%i] Idle Thread Priority: %u\r\n", i, tdp->td_priority);

This is the way im creating my 4 threads. setting the priority happens
"outside" the loop. Which is done because it is stated this way in the
docs.
After viewing the output, all 4 threads are created, but it doesnt get
to the part where the priority is lowered.

If i set the priority "inside" the loop, it gets set. 4 times
offcourse...
from one hand, its pretty obvious why this happens. the thread gets a
low priority and Nut/OS switches to the high priority main thread.
maybe im just being ignorant, but i dont understand what effect
NutThreadYield() has in an endless for loop. Because when the priority
gets set so low, the thread loses control over itself, thus, the way i
see it, isnt capable of forfilling his task by Yielding the thread...
maybe somebody can explain this a bit more.

i have also put a printf in the endless for loop, and when i declare the
priority inside the for loop, it spams alot onto the console.
i output the state the thread is in at that moment. After a while (and
this has been always around 1 minute) the spamming stops, and the system
locks up.
Could this have something to do with the NutThreadYield() and setting
the priority in the wrong way?

my questions have grown out to a long story, and i hope nobody minds
reading it :-)

Regards,
Yuri



More information about the En-Nut-Discussion mailing list