[ECOS] waiting for a thread to terminate
Øyvind Harboe
oyvind.harboe@zylin.com
Tue Aug 3 07:41:00 GMT 2004
I was wondering if this scheme is legal/recommended on eCos
when waiting for a thread to terminate. It seems to work fine:
struct args
{
cyg_handle_t caller;
};
static void invoker(cyg_addrword_t userData)
{
args *a=(args *)userData;
doWork();
// once the thread runs off the end of the universe, the scheduler is
// unlocked => it is not necessary to unlock the scheduler from
// the "caller" thread below.
cyg_scheduler_lock();
cyg_thread_resume(a->caller);
}
void foo()
{
....
cyg_thread_create(0,
invoker,
(cyg_addrword_t)&a,
"stack expander",
stack.get(),
stackSize,
&threadHandle,
&thread);
// start thread
cyg_thread_resume(threadHandle);
doSomethingElse();
setThreadTerminateFlag();
// at this point we will do nothing but wait for the other
// thread to complete.
// we'll be resumed by the thread above
cyg_thread_suspend(a.caller);
if (!cyg_thread_delete(threadHandle))
{
CYG_FAIL("Thread should be terminated by now");
}
}
--
Øyvind Harboe
http://www.zylin.com
--
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