• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Multithreaded drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: Overriding NSDocumentController problem
  • Next by Date: Re: Can't find mysql.h
  • Previous by thread: Re: Another filesystem mystery
  • Next by thread: [OT] Versions, Documentation, Frameworks
  • Index(es):
    • Date
    • Thread