On 17 May 2011, at 9:54 AM, Bing Li wrote:
> But I noticed that Cocoa threading provides wait/pulse-like synchronization
> techniques, such as Condition. I believe these techniques can be used to
> control a thread which has a while-true loop. So I think RunLoop can be
> replaced. Do you think so?

In a thread that you "own", you can certainly write in a style that does not 
use a run loop, and this is sometimes the best approach. However, if you are 
writing a GUI application, the main thread must be run loop based for the 
application to work, because Cocoa relies on the run loop.

The disadvantage of blocking on a Condition (or pthread mutex, etc.) is that 
the thread cannot respond to anything else while it is blocked there. An 
application must respond to a wide variety of things at any time. A run loop 
allows this to happen, but avoids many of the headaches involved with 
multithreaded programming (and you can always use threads in addition to run 
loops if that makes sense).

On 17 May 2011, at 11:37 AM, Bing Li wrote:
> Actually, I have tried a lot of time to find tutorials about how to program 
> RunLoop. Unfortunately, samples in the Apple Developer site are large and no 
> explanations. I have got more than 10 books. No one explains RunLoop at all. 
> Could you please offer me a small sample or some resources to learn RunLoop?

Here are some pages which might help you:

  http://en.wikipedia.org/wiki/Event_loop

  
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html
  especially "Anatomy of a Run Loop" and "When Would You Use a Run Loop?"

  
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to