• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why RunLoop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why RunLoop?


  • Subject: Re: Why RunLoop?
  • From: Wim Lewis <email@hidden>
  • Date: Tue, 17 May 2011 12:12:52 -0700

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 (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

  • Follow-Ups:
    • Re: Why RunLoop?
      • From: Uli Kusterer <email@hidden>
References: 
 >Why RunLoop? (From: Bing Li <email@hidden>)
 >Re: Why RunLoop? (From: Bill Bumgarner <email@hidden>)
 >Re: Why RunLoop? (From: Bing Li <email@hidden>)

  • Prev by Date: Re: Core Animation animations stop prematurely at random
  • Next by Date: Unrecognized document type
  • Previous by thread: Re: Why RunLoop?
  • Next by thread: Re: Why RunLoop?
  • Index(es):
    • Date
    • Thread