SemaphoreSync

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, they write to the terminal, artificially interrupted by a Kernel.Next for demo purposes. Thanks to the semaphore uart, 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

Build module SemaphoreSync with Astrobe, and create and upload the UF2 file using abin2uf2.

Set Astrobe’s memory options as listed, and the library search path as explained.

Repository