public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* Re: [ECOS] forwarded message from Satish Nayak
       [not found] <14555.15793.218299.995811@thinktwice.zoftcorp.dk>
@ 2001-09-05  0:09 ` Hugo 'NOx' Tyson
  0 siblings, 0 replies; only message in thread
From: Hugo 'NOx' Tyson @ 2001-09-05  0:09 UTC (permalink / raw)
  To: ecos-discuss


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-09-05  0:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <14555.15793.218299.995811@thinktwice.zoftcorp.dk>
2001-09-05  0:09 ` [ECOS] forwarded message from Satish Nayak Hugo 'NOx' Tyson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).