This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: forwarded message from Satish Nayak



> I have another silly doubt in thread.cxx file. In the function
> Cyg_HardwareThread::thread_entry why do u need to have the following loop?
> 
>     for(;;)
>     {
>         thread->entry_point(thread->entry_data);
>         thread->exit();
>     }
> Can I remove this loop and simply put following statements.
>         thread->entry_point(thread->entry_data);
>         thread->exit();
> Because the exit function anyway is going to remove the thread from the
> run queue.

Indeed.  Two answers:

1) if you then re-run the thread, as is permitted in some implementations
of some compatibility layers, it would fall off the end of the
thread_entry() function instead of going into the entry point again.
The thread->exit() is just a special sort of suspend, internally, so you
really can re-animate a dead thread!
[this is obsolete IIRC, but early versions of eCos used this feature]
[and it stays because some future compatibility layers might want it]

2) Defensive coding.  If, for some reason, the exit() returns, it's better
that your thread runs again - something a human might notice easily - than
storms off into no-stack-land and causes a complete mystery crash.

This rather begs the question: *why* do you want to remove that loop?
I see no possible gain here, aside from maybe one saved instruction that's
not normally executed.  I say maybe 'cos the end of the function is never
reached, so any return sequence can be omitted by the optimizer.  On ARM it
makes no difference at all, for example; there is a branch round some
literals to the exit sequence, or a branch back in that loop.  No
difference at all.

If you're enquiring because you're learning about eCos, that's great, keep
it up; but if you think your change is necessary to make some real project
or new port work properly, well.... ;-)

	- Huge

-- 
The 20th Century brought unprecedented increases in worldwide numeracy and
literacy and incredible advances in technology, science and mathematics.
It was also the only century in the past or in any reasonable predictable
future apparently to contain only 99 years.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]