FROM : Andrew Zamler-Carhart
DATE : Wed Jan 08 21:10:01 2003
Yuki,
Nathan Day has a good solution for inter-thread communications that is
simpler using Distributed Objects.
On Sunday, December 29, 2002, at 10:42 PM, Nathan Day wrote:
> I've got a class on my web site that does that and more, you can look
> at how that works or use it as is.
> http://homepage.mac.com/nathan_day/pages/source.html#NDRunLoopMessenger
Also note that performSelectorOnMainThread:withObject:waitUntilDone:
was introduced in Jaguar, so it won't work on 10.1.
Andrew
On Wednesday, January 8, 2003, at 06:43 PM, Hisaoki Nishida wrote:
> Hi,
>
> I am trying to figure out how to communicate between threads in a
> multithreaded application.
> I read Apple's documentation and it suggests using the NSObject
> instance method performSelectorOnMainThread:withObject:waitUntilDone:
> for this purpose.
>
> The method descrption says:
>
> - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
> waitUntilDone:(BOOL)wait
>
> Sends an aSelector message to the receiver (with arg as an argument)
> on the main thread. The main thread is the one in which the main run
> loop is run, which usually means the one in which NSApplication
> receives events. The method is performed when the main thread runs the
> run loop in one of the common run loop modes (as specified in the
> CFRunLoop documentation). If you pass YES for wait, the current thread
> blocks until the perform is completed on the main thread, otherwise
> the perform is queued on the main thread and this method returns
> immediately. If the current thread is the main thread, and you pass
> YES for wait, the message is performed immediately, otherwise the
> perform is queued to run the next time through the run loop. The
> receiver and arg are retained until the perform is finished. Note that
> you cannot cancel this perform request, unlike with the timed perform
> requests such as - performSelector:withObject:afterDelay:. See
> "Selectors" for a description of the SEL type. See "Selectors" for a
> description of the SEL type.
>
> In my case, I have a child thread fork from the main thread from my
> delegate. The child thread in turn again creates a child thread. This
> is where I want to send a message to my parent thread. But apparently
> this parent thread is not where NSApplication receives events, this is
> the thread that the root thread forked.
>
> If I want my leaf thread to send a message to its parent thread, what
> am I supposed to do?
> The receiver of the message is not in the leaf thread's scope, the
> receiver is in it's parent thread.
>
> I am tempted to do this:
>
> [receiverObj performSelectorOnMainThread:@selector(processMessage:)
> withObject:(id)someMessage waitUntilDone:NO]
>
> But receiverObj is in the parent thread.
> What am I supposed to do? I haven't a clue.
>
> Any help is appreciated,
>
> -yuki
DATE : Wed Jan 08 21:10:01 2003
Yuki,
Nathan Day has a good solution for inter-thread communications that is
simpler using Distributed Objects.
On Sunday, December 29, 2002, at 10:42 PM, Nathan Day wrote:
> I've got a class on my web site that does that and more, you can look
> at how that works or use it as is.
> http://homepage.mac.com/nathan_day/pages/source.html#NDRunLoopMessenger
Also note that performSelectorOnMainThread:withObject:waitUntilDone:
was introduced in Jaguar, so it won't work on 10.1.
Andrew
On Wednesday, January 8, 2003, at 06:43 PM, Hisaoki Nishida wrote:
> Hi,
>
> I am trying to figure out how to communicate between threads in a
> multithreaded application.
> I read Apple's documentation and it suggests using the NSObject
> instance method performSelectorOnMainThread:withObject:waitUntilDone:
> for this purpose.
>
> The method descrption says:
>
> - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
> waitUntilDone:(BOOL)wait
>
> Sends an aSelector message to the receiver (with arg as an argument)
> on the main thread. The main thread is the one in which the main run
> loop is run, which usually means the one in which NSApplication
> receives events. The method is performed when the main thread runs the
> run loop in one of the common run loop modes (as specified in the
> CFRunLoop documentation). If you pass YES for wait, the current thread
> blocks until the perform is completed on the main thread, otherwise
> the perform is queued on the main thread and this method returns
> immediately. If the current thread is the main thread, and you pass
> YES for wait, the message is performed immediately, otherwise the
> perform is queued to run the next time through the run loop. The
> receiver and arg are retained until the perform is finished. Note that
> you cannot cancel this perform request, unlike with the timed perform
> requests such as - performSelector:withObject:afterDelay:. See
> "Selectors" for a description of the SEL type. See "Selectors" for a
> description of the SEL type.
>
> In my case, I have a child thread fork from the main thread from my
> delegate. The child thread in turn again creates a child thread. This
> is where I want to send a message to my parent thread. But apparently
> this parent thread is not where NSApplication receives events, this is
> the thread that the root thread forked.
>
> If I want my leaf thread to send a message to its parent thread, what
> am I supposed to do?
> The receiver of the message is not in the leaf thread's scope, the
> receiver is in it's parent thread.
>
> I am tempted to do this:
>
> [receiverObj performSelectorOnMainThread:@selector(processMessage:)
> withObject:(id)someMessage waitUntilDone:NO]
>
> But receiverObj is in the parent thread.
> What am I supposed to do? I haven't a clue.
>
> Any help is appreciated,
>
> -yuki
| Related mails | Author | Date |
|---|---|---|
| Hisaoki Nishida | Jan 8, 18:46 | |
| Greg Hulands | Jan 8, 19:02 | |
| Andrew Zamler-Carh… | Jan 8, 21:10 | |
| Peter Bierman | Jan 8, 21:37 |






Cocoa mail archive

