I would like to use NSOperations
in my application to resolve threading problems. I have read some tutorials and now I know what I have to do, but I have a problem. There is a must to have the same NSOperationQueue
in each class. What if I use a new NSOperationQueue
in each class. There will be concurrency problems?
Asked
Active
Viewed 2,017 times
3

Rob
- 415,655
- 72
- 787
- 1,044

Infinite Possibilities
- 7,415
- 13
- 55
- 118
1 Answers
4
You only have concurrency issues if you access a resource from more than one thread. If your operations do not share some resources you should be fine, even with more than one NSOperationQueue running (NSOperationQueue does internally run more than one thread anyway).
If you share one NSOperationQueue across multiple threads, you should probably synchronize calls to it (using @synchronized(...)).

Alfonso
- 8,386
- 1
- 43
- 63
-
10Actually, the documentation states "Multicore Considerations: It is safe to use a single NSOperationQueue object from multiple threads without creating additional locks to synchronize access to that object." So adding synchronizing the calls is redundant. http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html#//apple_ref/doc/uid/TP40004592-RH2-SW5 – mikelikespie Jan 20 '11 at 02:07
-
But that's just for the calls like adding tasks to an NSOperationQueue. The actual tasks can run on multiple threads if the NSOperationQueue is concurrent, so tasks mustn't step on each others' feet. – gnasher729 Feb 26 '15 at 00:01