This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Seeking Thread join / waitpid equivalent.
I have just found this rather ugly code in the tftp_server.c
So it kills the tftp server thread...
cyg_thread_kill(server->thread_handle);
whangs the priority of the thread it killed as high as possible.
cyg_thread_set_priority(server->thread_handle, 0);
Waits a random period for it to die
cyg_thread_delay(1); // Make sure it gets to die...
Deletes the thread...
if (cyg_thread_delete(server->thread_handle)) {
If deleting the thread actually worked...
// Success shutting down the thread
Frees the memory associated with the thread..
free(server); // Give up memory
return 1;
}
Else ... we have a memory leak.
See why I'm looking for a cleaner way to do this?
On Fri, 27 Aug 2004, John Carter wrote:
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);
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
work.
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.
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