Take the 2-minute tour ×

Say, if timerFired (timer handler) is called by earlier set up using NSTimer or CADisplayLink, and touchesBegan is also called when a user touches the screen, can there be any race condition happening in the code inside the two handlers (timer handler and touch event handler)?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

If a timer handler and touchesBegan both run on the main thread, then there the code in them cannot intermix (they're on the same thread). This is the normal situation.

There can be race conditions in that the timer may run before or after the touchesBegan, but they can't run at the same time if they're on the same thread. They would only be on different threads if you attached the timer to another thread's runloop (which is a very unusual thing to do).

share|improve this answer
+1 for correct answer. –  Till Apr 27 '12 at 1:06
add comment

Your Answer


