This is the mail archive of the ecos-discuss@sources.redhat.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]
Other format: [Raw text]

Seeking Thread join / waitpid equivalent.


How about:


struct args
{
        cyg_handle_t caller;
};

static void invoker(cyg_addrword_t userData)
{
        args *a=(args *)userData;

	// this fn returns when the terminate flag is set
        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,
        "work",
        stack,
        stackSize,
        &threadHandle,
        &thread);
        
        // start thread
        cyg_thread_resume(threadHandle);
        
        doSomethingElse();

	// we do not want anyone else to run at this point
	cyg_sched_lock();

        setThreadTerminateFlag();

        // at this point we will do nothing but wait for the other
        // thread to complete.

        // we'll be resumed by the thread above when it exits
        cyg_thread_suspend(a.caller);
	cyg_sched_unlock();

        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


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