Should properties be atomic in NSURLConnectionDataDelegate (NSURLConnectionDelegate) when there are more concurrent connections and properties are accessed by methods being called when connection reaches particular state? There is no access from other threads to those properties invoked by me.

有帮助吗?

解决方案

NSURLConnection's concurrency is run-loop-based, so as long as all the connections for which your object is a delegate are started from the same run loop, you shouldn't need to worry about concurrency in your delegate. If you start multiple connections scheduled on different run loops, then yes, you would need to protect the private state of your delegate objects. Atomic properties are rarely sufficient for this.

In short, you either don't need to worry about this, or atomic properties are unlikely to help. One easy option would be to have all your delegate methods dispatch_async their work to a private serial GCD queue.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top