[ECOS] Seeking Thread join / waitpid equivalent.

John Carter john.carter@tait.co.nz
Fri Aug 27 03:44:00 GMT 2004

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.


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

ie. Fundamentally _any_ userland fix to this problem is not going to

The only hack I can think of is to use something like your thread
join, do the delete, test the result, if it failed sleep for a period,
repeat with exponential fall off on the sleep period.

Ugly ugly ugly.

John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand

The universe is absolutely plastered with the dashed lines exactly one
space long.

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list