Re: Timing distributed notifications
Re: Timing distributed notifications
- Subject: Re: Timing distributed notifications
- From: Jens Alfke <email@hidden>
- Date: Thu, 6 May 2010 10:57:16 -0700
On May 6, 2010, at 10:34 AM, McLaughlin, Michael P. wrote:
Is there a recommended way of determining that the currentRunLoop in a
subordinate task (executable) is, in fact, running and ready to
receive a
distributed notification?
No. That's really not what distributed notifications are for. They're
not a general purpose IPC mechanism, they're to notify some
unspecified set of listeners that something has happened, usually a
change in some system or app state (i.e. the system text highlight
color, or the current song in iTunes.) The assumption is that a
process that wasn't running when the notification was sent will check
the current state when it starts up anyway.
Later, after a File Menu selection in the app, the app informs the
subtasks
of the selection via
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"newCase" object:[notif object]];
You should come up with some other IPC mechanism to use here. This
kind of tightly coupled messaging isn't right for distributed
notifications. (In particular, be aware that distnotes can be dropped
on the floor if the receiving process's Mach message queue overflows.)
A typical way to do this is to use stdin/stdout for communication. To
send data to a subtask you write to its stdin pipe, and it sends you
data by writing to stdout. NSTask makes it fairly easy to set up these
pipes and monitor them asynchronously.
(Also, not meaning to sound patronizing, but are you sure you need to
run separate processes instead of just multiple threads? Inter-thread
communication is a lot simpler, and you avoid the performance and
resource overhead of spawning processes.)
—Jens_______________________________________________
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