Graphics Reference
In-Depth Information
Thread A has a lock on Object 1
Thread A
Object 1
Object 1 needs access to Object 2
Object 2 needs access to Object 1
Thread B
Object 2
Thread B has a lock on Object 2
FIGURE 12-6
A Theoretical Circular Lock
Mutlithreading with Filters
Unlike Core Animation, Core Image filters are not thread safe. This means that you
should only manipulate Core Image filters on a single thread. It is possible, however, to
adjust a filter on more than one thread by using key-value coding (KVC) and key paths to
manipulate the properties. For example, if you have a layer with a filter named acme and
it has a property named job , you can adjust it with code similar to the following:
[layer setValue:myValue forKeyPath:@”layer.filters.acme.job”];
The layer would guarantee that the change is atomic and, therefore, thread safe.
Threads and Run Loops
When working with Core Animation on multiple threads, you need to be aware that any
thread that calls -setNeedsDisplay on a layer is going to get the -display message as
well. If you flag a layer as needing the display from a thread other than the main thread,
you need to set up a run loop to ensure that the thread still runs when the - display call
occurs. If you don't, the -display call never occurs because the thread it is looking for
will have terminated, causing unexpected results.
Although it is possible to call -setNeedsDisplay from a thread other than the main
thread, it is a lot of work for very little effect or benefit. It is highly recommended that
these calls be localized to the main thread by utilizing -performSelectorOnMainThread: .
Search WWH ::




Custom Search