This is the mail archive of the ecos-discuss@sourceware.cygnus.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: Threads that end


jens.ohlund@secrc.abb.se wrote:
> 
> Hi !
> 
> Thanks for the confirmation. Now, how do I detect from another thread that one thread is "finished" so i can delete it ?

Internally the kernel tracks the state of the thread, and knows that it has
exited, but that type of implementation-dependent state information is not
wise to export in the official API. Really you should use some sort of
message passing primitive to indicate which threads have finished so you
can delete them.

A message box is probably the best primitive. Just before a thread leaves
its entry function, simply do:

cyg_mbox_put( mbox, cyg_thread_self() );

Then wherever it is you want to manage the deletion of threads, you do
something like:

cyg_handle_t th;
th = cyg_mbox_get( mbox );
while (!cyg_thread_delete( th )
  cyg_thread_delay(1);

> I don't have any locks in those two threads, so hanging on a resurce doesn't happen. I just want my memory back :).
> 
> But, just an idea, your giving a stack to the thread to run in. If the thread allocates any local variables, the are on the threads
> stack ?

Yes.

> Then I would be able to just kill the thread and then create a new thread, with the old "stack" as parameter to the cy_thread_create
> ?

Yes, but be sure to use cyg_thread_delete, not cyg_thread_kill if you are
doing this.

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

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