Page 1 of 1

Synchronize Multiple Threads

Posted: Fri Jan 16, 2015 6:13 pm
by Tabulous
Synchronize multiple threads, so as to make them all wait until say the system init is complete.

I'm thinking Events, so all the required threads calll chEvtWaitOne( EVENT_MASK(0) ); before the while(1);

Once system init is completed, call chEvtBroadcast( &eventsource ); and the threads waiting will come to life.


Is one to many feasible ?

Re: Synchronize Multiple Threads

Posted: Fri Jan 16, 2015 6:15 pm
by Giovanni
Hi,

Yes, it is feasible but why don't just create them after initialization?

Giovanni

Re: Synchronize Multiple Threads

Posted: Fri Jan 16, 2015 6:32 pm
by Tabulous
so this is my application structure

Code: Select all

int main(void)
{
    halInit();   
    chSysInit();

    initModuleA();
    initModuleB();
    initModuleC();
    initModuleD();

    while(1)
    {
        chThdSleepMilliseconds(1000);
    }
}

void  initModuleA(void)
{
init module vars etc

    chThdCreateStatic( MODWA,
                                 sizeof(MODWA),
                                 NORMALPRIO,
                                 ThreadFunc,
                                 NULL );
}


As you can see i normally create the thread when i call to initialize the module. What this means is the threads start to run.

I could put the chThdCreateStatic is another function that is called later, but this does not seem logical