Project 11: System V Semaphore Barrier

A barrier synchronization primitive using System V semaphores where N processes wait until all arrive.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages N/A
Difficulty Level 3 (Advanced)
Time Estimate See main guide
Knowledge Area Parallel Computing, Synchronization
Tooling See main guide
Prerequisites See main guide

What You Will Build

A barrier synchronization primitive using System V semaphores where N processes wait until all arrive.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Atomic multi-semaphore ops → Using semop with multiple sembuf
  • SEM_UNDO → Handling process crashes mid-barrier
  • Reusable barrier → Resetting for the next round

Key Concepts

  • Map the project to core concepts before you code.

Real-World Outcome

$ ./barrier_test --processes=5 --iterations=3

Barrier Test (5 processes, 3 iterations)

[P1] Reached barrier 1
[P3] Reached barrier 1
[P2] Reached barrier 1
[P5] Reached barrier 1
[P4] Reached barrier 1
--- All processes passed barrier 1 ---

[P2] Reached barrier 2
[P1] Reached barrier 2
[P4] Reached barrier 2
[P3] Reached barrier 2
[P5] Reached barrier 2
--- All processes passed barrier 2 ---

[P1] Reached barrier 3
[P5] Reached barrier 3
[P3] Reached barrier 3
[P4] Reached barrier 3
[P2] Reached barrier 3
--- All processes passed barrier 3 ---

All processes synchronized correctly. PASS

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: UNIX_IPC_STEVENS_VOL2_MASTERY.md
  • Primary references are listed in the main guide