Game of Life skeleton: how the goroutines and channels fit together
An animated model of the provided skeleton and one common way of filling its gaps. Messages travel along channels; click any box or channel to inspect it. It is a teaching model, not your solution, and your own design may differ.
provided and already wired declared but nil in the skeleton: you create it suggested addition (your design) the distributor body: you write it
Press a key in the SDL window:
What is happening
Press Start. The model begins at main() and follows the program: start-up, loading the image, evolving turns, the 2 s ticker, key presses, saving, and shutting down.
Inspector
Click a goroutine or a channel in the diagram.
The SDL window
frames drawn: 0dirty: false
The window only changes when a frame is drawn: on a 60 FPS tick, and only if a TurnComplete event has set dirty. Flips alone change a hidden pixel buffer.
Console (what the skeleton logs)
Message log
Things the skeleton warns about (and why)
A nil channel blocks forever on send or receive. In the skeleton, ioFilename, ioOutput and ioInput are nil: tick “skeleton exactly as provided” and start the model to see what that does.
ioCommand, ioIdle (and the three nil ones once you create them) are unbuffered: a send completes only when the other goroutine receives. The IO goroutine and the distributor must agree on the order of messages.
Send every CellFlipped or CellsFlipped for a turn beforeTurnComplete, which is what makes SDL draw a frame. Never send both kinds for the same cell, or it flips twice.
Before exiting, the distributor asks the IO goroutine whether it is idle (ioCheckIdle), so a PGM write is not cut short.
close(events) is how SDL learns to stop. Removing it may deadlock the program, as the skeleton comment says.
events has a buffer of 1000. If the reader stops, the buffer fills and the sender blocks, which is more likely if you send one event per flipped cell.
SDL reads one keyboard event per frame and sends it on keyPresses (buffer 10); your distributor must keep receiving from it, including while paused.