[ECOS] cyg_thread_kill and info threads

Hugo Tyson hmt@cygnus.co.uk
Mon Apr 10 08:15:00 GMT 2000

andrew.lunn@ascom.ch (Andrew Lunn) writes:

> Hi Folks
> Could someone explain to me what happens to a threads after you call
> cyg_thread_kill() on it. 
> Gdb's info thread shows the thread even though its been killed and
> i've deallocated all its memory and probably realocated the memory to
> another thread. Is the thread realy dead after calling
> cyg_thread_kill?
> My code dynamically creates and destroys threads and cyg_thread_create
> seems to have a problem once i have just over 100 threads either
> running or killed. It looks like one of the mlqueue queues becomes
> circular.  Before i debug this i would like an overview of what
> happens to killed threads? 

It depends on what the thread was doing (or if not running or ready, how it
was not running or ready).  Basically, they're forced to yield the cpu if
necessary and removed from all queues - but it may be necessary to let the
murder victim run to do that, if it's on a mutex queue for example (only
the thread itself knows what to do to dissociate it from whatever it was
waiting for).

The exception is the GDB thread info queue, where killed threads remain
recorded, since (in uITRON for example) you can trivially re-run the thread
and are expected to so do.

To remove it from the GDB thread info queue, first ensure it has actually
exited, then call the destructor ~Cyg_Thread().

The KAPI has a suitable utility:

   externC cyg_bool_t cyg_thread_delete( cyg_handle_t thread )
       Cyg_Thread *th = (Cyg_Thread *)thread;
       if( th->get_state() != Cyg_Thread::EXITED )
   	   th->kill(); // encourage it to terminate
       if( th->get_state() != Cyg_Thread::EXITED )
   	   return false; // it didn't run yet, leave it up to the app to fix
       return true;

If you get false out if this, fiddle with the victim's priority or yield
yourself, so that it runs, and try again.

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

More information about the Ecos-discuss mailing list