Search code examples
iosmultithreadingthread-safetynsoperationnsoperationqueue

Adding NSOperation from NSOperation


Is it safe to add new NSOperation to NSOperationQueue from the main() method of NSOperation? Should I suspend NSOperationQueue before adding? Are there any gotchas in this? Do I have to add that in main thread using dispatch_get_main_queue?


Solution

  • Yes it should be safe until you are accessing the queue with one thread. You may also use mutex to lock the queue while adding operation into it.