This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Seeking Thread join / waitpid equivalent.
On Fri, Aug 27, 2004 at 02:41:41PM +1200, John Carter wrote:
> On Thu, 26 Aug 2004, Billy wrote:
>
> >On Fri, Aug 27, 2004 at 12:02:00PM +1200, John Carter wrote:
> >I think the cyg_thread destruction question above is different from the
> >thread.join question below.
>
> Yes and no. What the guy was trying to do via a thread destructor
> would have been much more simply achieved via a thread.join in a
> reaper thread.
>
> thread_join(thread);
> cyg_thread_delete(thread.handle);
> free(thread.stack);
True only if his reaper were stalking a single thread. If his reaper is
stalking more than one, which would he join with first? Maybe this is
why I thought they were different questions.
> > void
> > thread_entry_function(cyg_addrword_t data)
> > {
> > struct myThreadType *thread = (struct myThreadType*)data;
> > (*thread->entry_function)(thread->data);
> > cyg_semaphore_post(&thread->death_semaphore);
> > }
> >
>
> > void
> > thread_join(struct myThreadType *thread)
> > {
> > cyg_semaphore_wait(&thread->death_semaphore);
> > }
> >
>
>
> So if you are doing something like..
>
> thread_join( &thread);
> cyg_thread_delete( thread.handle);
>
> unless the thread doing the join is of lower priority than the
> exiting thread there exists a narrow gap between the post and the end
> of cyg_thread_exit during which cyg_thread_delete can fail.
That's true. I see that I was only getting away with it because I don't
ever actually delete the expired thread.
> ie. Fundamentally _any_ userland fix to this problem is not going to
> work.
Apparently so! There are no hooks to mark the end of cyg_thread_exit()
and the thread_delete()-ability of a thread. Seems like they might be
useful in order to make cyg_thread_delete() practical without resorting
to priority acrobatics and unnecessary thread_delay calls. I'd hope
such a proposal would be more waitpid()-ish than join()-ish, to enable a
peer-priority reaper to stalk multiple victims.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss