How whitespaghet/panaderia works
Project Type & Purpose
• Panader-a is a standalone Python simulation of Lamport’s bakery algorithm for mutual exclusion.
• It uses the multiprocessing library to create concurrent processes that compete for a critical section, with ASCII‐art console output showing each process’s state.
Key Architectural Components
a. Master (Orchestrator) Process
• Initializes shared data structures (flags, tickets) via a multiprocessing.Manager or shared Array/Value.
• Spawns N worker processes.
b. Shared State Store
• A manager‐backed dictionary or shared arrays holding:
• choosing[i] flags
• ticket[i] numbers
c. Worker Processes (P0…Pn)
• Each executes the bakery protocol loop:
1. Set choosing[i] = True
2. Assign ticket[i] = 1 + max(ticket[0..n])
3. Set choosing[i] = False
4. Wait until for all j: (!choosing[j] && (ticket[j] == 0 || (ticket[i], i) < (ticket[j], j)))
5. Enter critical section & print ASCII state
6. Set ticket[i] = 0
7. Repeat
d. Critical Section (CS)
e. Console / ASCII Renderer
• Captures & displays process states; optional separate component or simply part of each worker’s output.
Relationships & Data Flows
• Master → Shared State: “initialize”
• Master → Worker Pi: “spawn”
• Worker Pi ↔ Shared State: “read/write choosing[] & ticket[]”
• Worker Pi → Critical Section: “enter when conditions met”
• Worker Pi → Console: “print ASCII status”
• Worker Pi → Shared State: “ticket[i] = 0 on exit”