SignalSync

Description

This program demonstrates the synchronisation between several threads with signals. It uses one core and the kernel.

There are four threads:

  • Thread 0: the usual blinker, period-triggered, “heartbeat” indicator
  • Threads 1 and 2: running the same code, they simply await a signal from thread 3, print a message, and await again. That is, these two threads are not triggered by periodic timing, but the reception of the signal. Both threads await the same signal.
  • Thread 3: periodically send the awaited signal.

Since both receiving threads 1 and 2 are awaiting the same signal, they take turns receiving it. There’s a variant, commented out, which sends the signal to both during the same cycle of thread 3.

Note: since the threads share one output terminal, the printed status messages need to be below the UART’s 32 char buffer size.

Output Terminal

See Set-up, one-terminal set-up.

Build and Run

Repository

  • libv2: for RP2040/Pico and RP2350/Pico2: SignalSync
  • lib (v1): this version is no longer being maintained: SignalSync