FROM : Peter Bierman
DATE : Wed Jan 08 21:37:03 2003
At 9:43 PM -0500 1/8/03, Hisaoki Nishida wrote:
>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.
Note that all the objects in your process are in _every_ thread.
Threads share a single address space. Objects are just blocks of RAM in this address space.
"performSelectorOnMainThread" allows an object to have its method executed by the main thread. The object, and any variables it accesses, are still simultaniously accessable from other threads.
This is most useful when carying out operations that affect the UI via AppKit. Most AppKit methods expect to be called from the same thread as the NSApplication runLoop.
If you need thread #3 to ask thread #2 to perform some operation, you'll need to use DO or some other form of cross-thread communication. DistributedObjects work by funneling all the operations through the run loops of the two threads.
Apologies if I'm stating something you already understand. :-)
-pmb
DATE : Wed Jan 08 21:37:03 2003
At 9:43 PM -0500 1/8/03, Hisaoki Nishida wrote:
>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.
Note that all the objects in your process are in _every_ thread.
Threads share a single address space. Objects are just blocks of RAM in this address space.
"performSelectorOnMainThread" allows an object to have its method executed by the main thread. The object, and any variables it accesses, are still simultaniously accessable from other threads.
This is most useful when carying out operations that affect the UI via AppKit. Most AppKit methods expect to be called from the same thread as the NSApplication runLoop.
If you need thread #3 to ask thread #2 to perform some operation, you'll need to use DO or some other form of cross-thread communication. DistributedObjects work by funneling all the operations through the run loops of the two threads.
Apologies if I'm stating something you already understand. :-)
-pmb
| 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

