Page 1 of 1

Semaphore Wait/Reset

Posted: Thu Dec 15, 2016 8:21 am
by Tabulous
when using a binary semaphore does one need to use the chBSemReset before chBSemWait? see usage below

// Initialized like this
chBSemObjectInit( &sLock, true );


// Signal sent from Ext interrupt or timer
chBSemSignalI( &sLock );

// usage like this

Code: Select all

    while( TRUE )
    {
        chBSemReset( &sLock, true );

        status = chBSemWait( &sLock );

        if( status == MSG_OK )
        {
           // do some work
   }
   }


I ask as it seems to work with or without it

Re: Semaphore Wait/Reset

Posted: Thu Dec 15, 2016 9:25 am
by Giovanni
Hi,

You don't need to reset it. Actually it Can lead to an incorrect behavior.

Giovanni

Re: Semaphore Wait/Reset

Posted: Thu Dec 15, 2016 6:43 pm
by Tabulous
Thanks :-)