Semaphore Wait/Reset

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

Semaphore Wait/Reset

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

Re: Semaphore Wait/Reset

Post by Giovanni »

Hi,

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

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

Re: Semaphore Wait/Reset

Post by Tabulous »

Thanks :-)
Post Reply