• 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: What's better a separate run loop or separate thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's better a separate run loop or separate thread?


  • Subject: Re: What's better a separate run loop or separate thread?
  • From: Fritz Anderson <email@hidden>
  • Date: Sun, 11 Jul 2004 23:07:45 -0500

On 11 Jul 2004, at 9:28 PM, Ken Tozier wrote:

I don't know if it's just dumb luck on my part (I've only been using threads for about two weeks) but I didn't notice any problems sending notifications from threads. I just post them from inside the thread and they magically arrive at their destination.

Maybe a little more magically than you mean: The problem is not whether the NSNotifications get delivered. They'll get delivered. The problem is that they are delivered on the same thread they were sent from.

This means the notification handler in your Class X can interrupt a Class X method (on the main thread) in the middle, and make changes to the instance variables. And then permit that main-thread method to resume, with its data changed (one might say magically) out from under it.

You see the problem. Unless you are very careful or lucky to avoid collisions between the notifications and the main-thread business, pain and sorrow will befall you.

-- F
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: What's better a separate run loop or separate thread? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Determining if a method is a class or instance method
  • Next by Date: Re: VTK and Cocoa on Mac OS X
  • Previous by thread: Re: What's better a separate run loop or separate thread?
  • Next by thread: 1 REALLY STUPID question Cocoa support for AppleScript
  • Index(es):
    • Date
    • Thread