Description
This program demonstrates the synchronisation between threads with semaphores to access the same shared resource, namely the UART for printing their messages. It uses one core and kernel.
There are three threads:
- Thread 0: the usual blinker, period-triggered, “heartbeat” indicator
- Thread 1 and 2: running the same code, writing to the terminal, artificially interrupted by a
Kernel.Next
for demo purposes. Thanks to the semaphoreuart
, they nonetheless correctly share the output channel without interfering, taking turns.
Since the access to the terminal is now gated by the semaphore, the output strings can be any length (unlike with SignalSync, see note).
See Also
Output Terminals
See Set-up, one-terminal set-up.
Build and Run
Repository
- libv2: for RP2040/Pico and RP2350/Pico2: SemaphoreSync
- lib (v1): this version is no longer being maintained: SemaphoreSync