next up previous
Next: Threading Up: Adding a Graphical User Previous: Exercises

GTK main loop vs Simulation main loop

When the GTK Controller is run, you may notice that when you click start, the controller is unusable until the simulation is finished. What if we wanted to have a stop button? What if we wanted to change some parameter on the fly, such as turn the text rendering on or off, or change the speed of the simulation?

The reason for the controller being unusable while the simulation is running, is that there are two loops that need to run at the same time. The first loop is the GTK loop. It waits for a widget to emit a signal, and then calls any attached callbacks. The GTK loop has to be running in order for any of these callbacks to happen. The second loop is the simulation loop. It needs to keep running in order to do the calculations and move the atoms.

In order to both run the simulation and use the GTK controller at the same time, we need to run both loops concurrently. The simplest way to do this is using threading.


next up previous
Next: Threading Up: Adding a Graphical User Previous: Exercises
James Roper 2004-02-12