views:

240

answers:

2

I know that drawLayer: and drawlayer:inContext: are called on multiple threads when using a CATiledlayer, but what about drawRect:?

Apple's PhotoScroller example code uses drawRect: to get its images from disk, and it has no special code for handling threads.

I am trying to determine whether my model for a CATiledLayer must be thread-safe.

+1  A: 

Have you seen this technical Q&A from Apple?

It doesn't answer your question directly, but it could help you decide how to implement your model.

Matt Long
That article contains a contradiction, but it pretty much says you have to be threaded. Watching the WWDC session video gives me one more piece of the puzzle that convinces me that this is the case.
Steve Weller
A: 

Yes, drawRect can and will be called on multiple threads (tested on OS 4.2).

This behaviour is less obvious if your drawing is fast enough to outpace the arrival of new zoom gestures so your app may work fine until tested with rapid input of zoom gestures.

One alternative is to make your model thread-safe.

If thread-safety is achieved by synchronizing most of the access to the data model to one drawing thread at a time then then you might do just as well to mutex the boy of drawRect with something like @syncrhonize(self) which seems to work.

I haven't found a way to request that CATiledLayer only uses one background thread.

persiflage