• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

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.

Connections