Skip to content

Operating systems

BatchServe

A C program that simulates a restaurant serving customers in strict batches, using threads, semaphores and a fair queue.

BatchServe, sketched

Context

The problem

Classic concurrency problems are easy to explain and very easy to get slightly wrong.

Approach

How I built it

  1. POSIX threads and semaphores keep each batch in step.

  2. A first-come, first-served queue with checks so nobody waits forever.

  3. Animated terminal logs, so you can actually watch the threads take turns.

Result

What came out of it

  • No deadlocks or starvation

  • Fair ordering

  • Concurrency you can watch