Re: [[NSNotificationCenter defaultCenter] postNotificationName] from a thread?
Re: [[NSNotificationCenter defaultCenter] postNotificationName] from a thread?
- Subject: Re: [[NSNotificationCenter defaultCenter] postNotificationName] from a thread?
- From: Frank Midgley <email@hidden>
- Date: Mon, 3 Nov 2003 10:39:54 -0600
On Nov 1, 2003, at 2:12PM, Michael Rothwell wrote:
I'm writing an application that has several worker threads and uses
notifications. i'm worried about thread safety. In the worker threads,
I'm sending notifications back to the main thread like this:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"UPnPDiscovery" object:self userInfo:d];
The main thread has registered for these notifications, and runs a
method, etc.
Should I be doing something to ensure thread safety?
If you need to support pre-Jaguar systems that don't have
-performSelectorOnMainThread:withObject:waitUntilDone: then this code
will definitely run into thread safety issues. The methods that were
set up as observers of the notification will actually be run in the
thread where the notification is posted. It makes no difference which
thread added the observer. (This is different from distributed
notifications where there is no guarantee at all which thread will
observe the notification and call the methods.)
In either case to guarantee running on the main thread you'll need DO
or a similar mechanism to communicate with the main thread.
-Frank
------------------------------------
Frank M. Midgley
email@hidden
http://homepage.mac.com/knarf/
_______________________________________________
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.