Skip navigation.
 
mlRe: drawing in a separate thread
FROM : Kyle Sluder
DATE : Fri May 02 10:13:27 2008

On Fri, May 2, 2008 at 3:13 AM, Graham Cox <graham.<email_removed>> wrote:
>  I realise these questions must sound rather fundamental, but nothing in the
> Cocoa Drawing Guide or Thread Guide really addresses them. I have used
> threads before to perform tasks not involving drawing, so I'm not completely
> unfamiliar with them, but I haven't tried drawing on a secondary thread
> before.


The reason these questions aren't addressed in the guide is because
they are highly dependent on just what you are doing.  Only you can
determine when something needs to be updated.

As for spawning multiple threads, you want your drawing to be
performed really quickly.  I would strongly advocate keeping a thread
around for the life of your view and having it sit an a loop that ends
with it performing a blocking read on some IPC port.  That way it gets
scheduled off the processor but you don't suffer the thread-creation
or -destruction penalty every time you perform a draw.

Drawing from a secondary thread isn't an easy task, so perhaps you
might want to consider whether it's possible to avoid doing so.  Maybe
you can draw into an image on the secondary thread, and then when
necessary use -performSelectorOnMainThread:withObject:waitUntilDone:
to send the view a -setNeedsDisplay: message when after your thread
has completed its drawing.  Then the view can overwrite its own buffer
with it.  Be careful of synchronization issues, of course.

HTH,
--Kyle Sluder

Related mailsAuthorDate
mldrawing in a separate thread Graham Cox May 2, 09:13
mlRe: drawing in a separate thread Kyle Sluder May 2, 10:13
mlRe: drawing in a separate thread Graham Cox May 2, 13:07
mlRe: drawing in a separate thread Jean-Daniel Dupas May 2, 13:20
mlRe: drawing in a separate thread Jens Alfke May 2, 17:27
mlRe: drawing in a separate thread Graham Cox May 2, 17:30
mlRe: drawing in a separate thread Jean-Daniel Dupas May 2, 18:04
mlRe: drawing in a separate thread Duncan May 3, 05:40
mlRe: drawing in a separate thread Graham Cox May 3, 06:51
mlRe: drawing in a separate thread Duncan May 3, 13:36
mlRe: drawing in a separate thread Jean-Daniel Dupas May 3, 13:57
mlRe: drawing in a separate thread Graham Cox May 3, 14:52
mlRe: drawing in a separate thread Jean-Daniel Dupas May 3, 15:22
mlRe: drawing in a separate thread Graham Cox May 3, 15:30
mlRe: drawing in a separate thread Ricky Sharp May 3, 15:44
mlRe: drawing in a separate thread Jean-Daniel Dupas May 3, 15:55
mlRe: drawing in a separate thread Graham Cox May 3, 16:11