public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] waiting for a thread to terminate
@ 2004-08-03  7:41 Øyvind Harboe
  0 siblings, 0 replies; only message in thread
From: Øyvind Harboe @ 2004-08-03  7:41 UTC (permalink / raw)
  To: ecos-discuss

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-08-03  7:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-03  7:41 [ECOS] waiting for a thread to terminate Øyvind Harboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).