many messages between threads
many messages between threads
- Subject: many messages between threads
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 1 Sep 2007 14:36:39 +0200
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.
If it does:
[mainDirect performSelectorOnMainThread: @selector(add:) withObject:
[NSNumber numberWithInt: someInt ] waitUntilDone: NO];
it takes 250 µsec - but the user interface becomes unusable.
If Worker does the same, but with waitUntilDone: YES, the user
interface is responsive again, but it takes 20 msec - same as the
proxy call.
If Worker does:
[mainDirect add: [NSNumber numberWithInt: someInt ]];
it takes 450 µsec - but this looks somehow dangerous. Could possibly
made save with the use of NSLocks.
If Main does:
[self add: [NSNumber numberWithInt: someInt ]];
it takes 150 µsec, but, of course, the user interface is blocked for
the duration of the loop.
So: how to get messages between threads safely and fast?
Kind regards,
Gerriet.
_______________________________________________
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