The Multi-Threaded Game of Life Sample

Links: Up

Links: Build Script

Links: Run the sample (after building)

Links: Sample Project File for Visual Studio

This sample shows how to do advanced multi-threaded GUI (Graphical User Interface) programming where worker threads compute the results of an algorithm, in this case the Game of Life. This is one of the most advanced samples, exploiting many novel features of F# not found in other languages.

The F# code in alg.fs is the core computation of the rules of the Game of Life on a grid. An array of cells is used for obvious efficiency and simplicity reasons. The external interface to this component is alg.fsi.

The F# code in worker.fs specifies the reactive computation machine that runs on the worker thread (but not the worker thread itself). The automata is specified as a set of recursive functions (which represent a state machine, i.e. they block waiting for input when the machine enters the 'Paused' or 'Finished' states), and is paramaterized by callbacks that provide the interface to the GUI.

The GUI and thread control logic can be found in client.fs. The specification of the GUI uses F#'s reactive 'runtime-checked' recursion.

Suggested Exercises