Binary semaphores vs Thread suspension

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
jayalfredprufrock
Posts: 36
Joined: Tue Jan 13, 2015 6:33 am
Has thanked: 8 times

Binary semaphores vs Thread suspension

Post by jayalfredprufrock »

I was hoping if somebody could offer some design advice regarding the use case for binary semaphores.

In a situation where you have a hardware interrupt (eg. rx buffer full) and you want to signal to another thread to parse the data packet, is there any advantage of using a binary semaphore instead of simply putting the parsing thread asleep and waking it up from the interrupt? Both seem to work without any noticeable differences but since I do this kind of thing so often I just wanted to make sure there wasn't a reason to use one technique over the other. Thanks!
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Binary semaphores vs Thread suspension

Post by Giovanni »

Hi,

Binary Semaphores are larger but there can be multiple threads waiting on them. The suspend pointer can only accommodate one thread waiting.

The difference is also that the semaphore can buffer one event (taken to not taken transition) while the suspend point is synchronous, you have to put it in a critical zone and check a condition externally before going to sleep.

Basically it depends on your requirements, the HAL uses both modes in various drivers.

Giovanni
Post Reply