This repository demonstrates the classic concurrency puzzle known as the Santa Claus Problem, originally described by John Trono. The problem requires synchronizing Santa, nine Reindeer returning from vacation, and a group of Elves needing Santa's help — ensuring that Santa only wakes up under the proper conditions. It highlights important concurrency concepts like resource sharing, scheduling, and synchronization constraints.
SantaDemo.mp4
-
C++ Code
- Provides two versions of the Santa Claus solution:
- santa_bug.cpp - The original approach (contains a known scheduling assumption bug).
- santa.cpp - A fixed solution properly handling the bug.
- Provides two versions of the Santa Claus solution:
-
Python Visualization
- A Tkinter-based GUI that launches the C++ program in the background and animates Santa, Reindeer, and Elves.
- Displays concurrency events, reindeer arrivals, and elves' help requests in an interactive way.
g++ -std=c++20 santa.cpp -o santa
python3 santa_ui.py
- Concurrency: The Santa Claus Problem illustrates how multiple threads (or processes) can coordinate access to shared resources and synchronization primitives.
- Scheduling Pitfalls: The classic solution can fail if threads are not scheduled as assumed. This repo showcases both the original approach and the improved fix.
- Real-World Relevance: Understanding concurrency is essential for designing reliable, multi-threaded applications.