Is drawRect: calling multiple threads when using CATiledlayer?

I know that drawLayer: and drawlayer:inContext: cause multiple threads when using CATiledlayer , but what about drawRect: :?

Sample Code Apple PhotoScroller uses drawRect: to retrieve its images from disk, and it does not have special code to handle streams.

I am trying to determine if my model for CATiledlayer should be thread safe.

+4
source share
3 answers

Have you seen this technical Q&A from Apple ?

It does not directly answer your question, but it can help you decide how to implement your model.

+1
source

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

This behavior is less obvious if your drawing is fast enough to get ahead of the appearance of new zoom gestures, so your application can work fine until it is tested with quick input of zoom gestures.

One option is to make your model thread safe.

If thread safety is achieved by synchronizing most of the access to the data model with one drawing stream at a time, then you can do the same as mutex for the drawRect body with something like @syncrhonize (self), which seems to work.

I did not find a way to request that CATiledLayer use only one background thread.

+2
source

I found that CATiledLayer uses several background threads in iOS Simulator, but one background thread on my iPhone.

My Mac has a dual-core processor, while my iPhone has one core (A4).

I suspect an iOS device with an A5 processor will also use multiple threads.

+2
source

Source: https://habr.com/ru/post/1313135/


All Articles