Re: Timer and RunLoop question
Re: Timer and RunLoop question
- Subject: Re: Timer and RunLoop question
- From: Wim Lewis <email@hidden>
- Date: Tue, 29 Sep 2009 14:30:20 -0700
On Sep 29, 2009, at 2:09 PM, Gabriel Zachmann wrote:
I've got an app that handles keyboard input (-keyDown:) and has a
repeating timer that causes the runloop to call repeatedly a method
in my app (called timerFireMethod:).
Could it happen that keyDown: and timerFireMethod: are running at
the same time?
No. A run loop lives in a particular thread (or, I guess, each thread
has an associated run loop), and it invokes things serially, in its
thread. There happens to be one "main" run loop that receives all the
UI events and so on.
This has pluses and minuses, of course: on the one hand, you can't
take advantage of parallelism as easily; on the other hand, event-loop
programming is much easier to do correctly than full multithreaded
programming, since you know that other code will only run in between
events (or if you recursively invoke the run-loop, as in a modal panel).
And what about two timers, i.e., what happens, if one of them fires
while the method associated with the other one is till executing?
It won't be able to fire until control returns to the runloop in some
way.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden