On Apr 12, 2010, at 8:46 AM, Rasmus Skaarup wrote:

>> Try simplifying your app by eliminating the use of background threads.  Or, 
>> if you feel you must use background threads for long-running computation, 
>> use them only for handling the data after receiving it.  Do everything 
>> involving launching the task and initiating background reads of its output 
>> from the main thread (without that bizarre bit about launching a background 
>> thread just to have it shunt some work back to the main thread).
> 
> I thought that when I added the observers from the main init, and started the 
> tasks by doing performSelectorOnMainThread: from the background thread, it 
> would also start the task on the same thread as the observers - the main 
> thread. But to my suprice, if I add specific observers from startMyTask: 
> (instead of from the main init) everything works perfectly, even though I 
> still initate the task launch from a background thread. 
> 
> Thanks for your help Ken!

You're welcome, but the above still demonstrates quite  a bit of confusion 
about threads.  The reason I told you to remove the (apparently unnecessary) 
threading from your app was because, no offense, I don't have confidence that 
you're getting it right.  And getting the threading wrong is very likely to 
produce symptoms like you described.

For example, the phrase "on the same thread as the observers" makes no sense.  
Observers don't have or live on a specific thread.  Whatever thread a 
notification is posted on, that's the thread where the observers' methods are 
invoked.  Notification delivery is just a one-step-indirect method invocation.  
Posting the notification is exactly the same as looping through a list of the 
observers and just directly invoking their registered selector.

Second, the "main" init (whatever that means) may be, but is not necessarily, 
invoked on the main thread.  It depends on how you wrote things.  But it 
shouldn't matter, in terms of where you register observers of notifications.  
Registering observers with the default notification center means they are 
registered with the notification center, period.  That's true across all 
threads.  The notification center and registrations with it are not 
thread-specific.

The fact that neither of us understands why the change you made has "fixed" the 
problem means I have no confidence in it, and neither should you. You need to 
actually understand what's going on and why.

Regards,
Ken

_______________________________________________

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