I have a function drawView
which is thread safe and does drawing for short periods of game animation. I have functions startAnimating
and stopAnimating
. I want a background thread to call drawView
at a regular rate but only during the period that the animation is enabled.
In startAnimating
I was going to call the view's performSelectorInBackground:withObject:
to get the thread running.
I'm a little confused about how to do the thread communication and initialize the drawing thread: specifically, setting up a runloop to receive display link messages and then at the end notifying the thread that it should exit and exiting the run loop cleanly when stopAnimating
is called from the main thread. I want to ensure that drawView
is never called after stopAnimating
, and also that the drawing thread is not cancelled abruptly in the middle of the drawing operation. I have seen a lot of very poor answers to this kind of question on line.