views:

54

answers:

1

I have two threads main thread and worker thread. What I want to be able to do is schedule callbacks (delegates) to the worker thread irrespective of who calls functions that trigger those delegates. For example:

/* mainThread */
[Obj asyncCallback]; // triggers callback to delegate foo()

/* Worker thread should do all the callback processing. i.e when foo() is called [NSThread currentThread] should always give worker threads ID and never main threads ID. */
A: 

Probably the easiest option is -performSelector:onThread:waitUntilDone:. You'll need to make sure your worker thread starts a run loop.

JeremyP
The delegates I am talking about are kernel generated i.e I am some call that will be performed async. When the task is completed kernel checks if the expected callback is present or not and if it is present then it will notify that callback. I don't think performSelector will work in my case.
blacklife
Your example was an Objecive C message. If you can do [obj asyncCallback] you can do -performSelector:onThread:waitUntilDone: provided you have an NSThread object and the thread is in a run loop.
JeremyP