Re: many messages between threads
Re: many messages between threads
- Subject: Re: many messages between threads
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sat, 1 Sep 2007 09:08:57 -0700
On Sep 1, 2007, at 05:36, Gerriet M. Denkmann wrote:
I have a tree-like data structure which is displayed in an NSBrowser
and gets operated upon.
As these operations can take some time, they are done in another
thread.
In order to test the message speed I created a simpler case:
One object - called Main - lives in the main thread and another -
called Worker - lives in another thread.
Main has a method:
- (void)add: (NSNumber *)n { myInt += [ n intValue]; }
Worker has:
mainProxy an NSProxy for Main
mainDirect = Main (not a proxy)
If Worker does (in some loop)
[mainProxy add: [NSNumber numberWithInt: someInt ]];
this takes about 20 msec (iBook G4 800 MHz) per operation.
Make sure to use setProtocolForProxy: on mainProxy, if you haven't
already. You could also declare add: as (oneway void) if your worker
thread doesn't depend on the result of that operation. You could also
just use the primitive value as -(void)add:(int)n { mInt += n; } if
you're using DO.
If it does:
[mainDirect performSelectorOnMainThread: @selector(add:)
withObject: [NSNumber numberWithInt: someInt ] waitUntilDone: NO];
it takes 250 µsec - but the user interface becomes unusable.
If you're calling it on every pass through the loop, you likely need
to batch your results or have the main object retrieve them at
intervals.
So: how to get messages between threads safely and fast?
For my applications, DO has been fast enough. Without seeing your
code or knowing what you're trying to do outside of a contrived
example, I doubt that anyone can make a reasonable assessment of your
problem. Are you sure that messaging is what you need to optimize?
regards,
Adam_______________________________________________
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