Threading and NSViews
Threading and NSViews
- Subject: Threading and NSViews
- From: Karim Morsy <email@hidden>
- Date: Mon, 20 Mar 2006 22:28:11 +0100
thanks for the hint, kaelin!
as far as threading is concerned, I have one more question about views.
so far I've been drawing a view on the main thread and redrawn it
with a timer every 0.02 seconds. to save performance, instead of
firing the timer on the main thread I would like to perform the
drawing on a secondary thread that runs in a while(true) loop, sleeps
for 0.02 seconds and repeatedly redraws the view.
so far I've been doing this (to periodically draw 4 views):
- I detach the drawing thread
- within that thread I do:
BOOL canDraw = [mView[i] lockFocusIfCanDraw];
if(canDraw) {
[mView[i] updateView: &values]; // in updateview: I do some
calculations and then call setneedsdisplay on self
[mView[i] unlockFocus];
}
- sleep for 0.02 seconds
-repeat
so far, most of the time this has been working fine, except for some
tiny mis-drawings that sometimes occur (from which I assume that I'm
missing something here).
I've read several articles and docs about multithreading in cocoa and
it's said one has to be really cautious when drawing on seperate
threads.
so I'm wondering wether the approach above is a good and most
importantly correct one + is there a better / more efficient
alternative ?
thanks again,
Karim
On Mar 20, 2006, at 8:56 PM, Kaelin Colclasure wrote:
On Mar 20, 2006, at 11:52 AM, Kaelin Colclasure wrote:
On Tiger and later systems, you can use Darwin notifications. Any
thread can register for them, and they are trivial to post:
notify_post("self.fileInitCompletedNotification");
If you elide the "self." prefix, they can even cross process
boundaries.
I should rather say, "If you replace the "self." prefix with a
reverse domain name prefix (e.g. "com.example.")..." (This
mitigates the problem of name collisions.)
-- Kaelin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden