IT lexicon › Programming › Binary semaphore

Binary semaphore

Programming På svenska → Updated: 2026-11-04

A semaphore that can only be 0 or 1, used in an RTOS mainly so an interrupt handler can wake up a task.

The textbook pattern: a UART interrupt receives a byte, gives the semaphore and returns. A task blocked on the semaphore wakes up and does the heavy lifting outside interrupt context. In FreeRTOS the calls are xSemaphoreGiveFromISR and xSemaphoreTake. If two interrupts fire before the task gets to run, they merge into one — the semaphore can't count to two.

It looks like a mutex but isn't one. A mutex has an owner who is expected to give it back, which is what lets the RTOS apply priority inheritance. A binary semaphore has no owner; anyone can give it. Use one as a lock and priority inversion comes free with it. FreeRTOS now recommends task notifications for the same job, since they're faster and use less RAM.

← Back to the lexicon