• ↑↓ to navigate
  • ↵ to open
  • ⟶ to select
  • ⌘ ⌥ ↵ to open in a panel
  • ←→ to navigate
  • esc to dismiss
⌘ '
keyboard shortcuts

Framing

Compare binary semaphores (mutex) versus counting semaphores (resource pools) — their use cases, behavior, and when to use each.

Comparison

FeatureBinary SemaphoreCounting Semaphore
Values0 or 1 only0 to N (N = resource count)
Use CaseMutual exclusion (critical section)Resource pool management
Initial Value1 (unlocked)N (available resources)
Negative ValueNever negativeNegative = number of waiters
ExampleFile lock, mutexBuffer slots, printer pool

Key Insights

  1. Binary semaphore = mutex — ensures only one process enters critical section
  2. Counting semaphore = resource counter — tracks pool of identical resources
  3. Both use same wait()/signal() operations — the difference is initialization and interpretation
  4. Binary semaphores can be implemented with counting (just set N=1), but not vice versa
  5. Classic use: producer-consumer — uses counting (empty, full) + binary (mutex)
  6. Priority inversion affects both types — high-priority process blocked by lower-priority holder

Synthesis

Binary semaphores are a special case of counting semaphores (N=1). Use binary for mutual exclusion, counting for resource pools. The producer-consumer problem elegantly combines both: counting semaphores (empty, full) manage buffer slots, while a binary semaphore (mutex) protects the buffer data structure.

Visual Explanation

semaphore_types A Semaphore Types Input B Semaphore Types Core Mechanism A->B triggers C Semaphore Types Output B->C produces

Semantic Network

semantic_semaphore_types THIS Semaphore Types REL1 Related Concept THIS--REL1 related REL2 Builds Into THIS--REL2 builds into

Connections