This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
waiting for a thread to terminate
- From: Øyvind Harboe <oyvind dot harboe at zylin dot com>
- To: ecos-discuss at sources dot redhat dot com
- Date: Tue, 03 Aug 2004 09:41:14 +0200
- Subject: [ECOS] waiting for a thread to terminate
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