Part 4: Synchronization and Inter-Thread Communication

This section covers kernel objects for thread synchronization and data passing in detail.

What You’ll Learn

  • Mutexes for mutual exclusion
  • Semaphores for signaling and counting
  • Condition variables for complex synchronization
  • Spinlocks and atomic operations
  • Message queues, FIFOs, LIFOs
  • Pipes and mailboxes
  • Events and polling
  • Zbus publish-subscribe messaging

Chapters

Chapter Description
Mutexes Mutual exclusion and priority inheritance
Semaphores Counting and binary semaphores
Condition Variables Wait with predicate pattern
Spinlocks ISR-safe locking and atomics
Message Queues Fixed-size message passing
FIFOs and LIFOs Variable-size data passing
Pipes and Mailboxes Byte streams and sync messaging
Events and Polling Multi-event waiting
IPC Selection Guide Decision flowcharts
Zbus Publish-subscribe message bus

When to Use What

flowchart TD
    A[Need to communicate?] --> B{Protect shared data?}
    B -->|Yes| C{ISR context?}
    B -->|No| D{Pass data?}

    C -->|Yes| E[Spinlock]
    C -->|No| F[Mutex]

    D -->|Yes| G{Fixed size?}
    D -->|No| H{Signal event?}

    G -->|Yes| I[Message Queue]
    G -->|No| J[FIFO/LIFO]

    H -->|Yes| K[Semaphore/Events]
    H -->|No| L[Condition Variable]

Choosing the right synchronization primitive is crucial for correctness and performance.


Table of contents


Back to top

Zephyr RTOS Programming Guide is not affiliated with the Zephyr Project or Linux Foundation. Content is provided for educational purposes.

This site uses Just the Docs, a documentation theme for Jekyll.