Synchronize Multiple Threads

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Synchronize Multiple Threads

Post 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 ?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Synchronize Multiple Threads

Post by Giovanni »

Hi,

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

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Synchronize Multiple Threads

Post 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
Post Reply