Multithreaded drawing
Multithreaded drawing
- Subject: Multithreaded drawing
- From: John Saccente <email@hidden>
- Date: Tue, 26 Feb 2002 01:03:00 -0600
For purely academic purposes, I'm experimenting with multithreaded
drawing. My main thread's drawRect: is empty, and I detach two
NSThreads which render continuously into a shared view:
while (keepDrawing)
{
if ([self lockFocusIfCanDraw])
{
... draw stuff ...
[[self window] flushWindow];
[self unlockFocus];
}
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
This works fine, as far as I can tell. However, I got the impression
that lockFocusIfCanDraw would act as a lock which arbitrated access to
the shared view such that, while one thread was inside the locked block
of code, the other would be blocked as well (or would at least spin
through the loop aimlessly waiting for lockFocusIfCanDraw to return
true.) To test the supposition, I put a 1 second sleep inside of the
locked block (why does that remind me of Al Gore?) in one of the
threads, but not in the other. I expected *both* threads to exhibit the
delay, but the second thread just chugged along at full speed. The docs
mention that graphics state info exists on a per-thread basis, though,
so I suppose I'm just not quite getting the big picture. What really
confuses me, though, is that while the additional delay didn't
*directly* interfere with the rendering in the second thread, it *did*
interfere when I tried to play with any UI widgets. That is, as I
dragged a scrollbar or slider, the UI tracking went all wonky and the
drawing would suddenly grind to a crawl (whereas without the extra sleep
call, the drawing ran in all of its asynchronous glory in concert with
the UI.)
Any info welcome.
John Saccente
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.