Get the pause / resume / stop controls working smoothly even when a delay is set.

The main problem encountered is that cached data keeps being delivered after pause; this code uses a mutex to
make the data delivery stop at the exact point a pause happens at, and resume when the simulation is unpaused.