Challenge: TiltShiftOperations in OperationQueue | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9461083-ios-concurrency-with-gcd-and-operations/lessons/26

Hello. So when multiple operations in an OperationQueue(not serial) try to append an element to the same array at the same time, what is happening?

Also, did you need the serial appendQueue when the filterQueue is serial also?

hi Victoria! I’ll try to answer both questions here.

The serial queue appendQueue controls access to the filteredImages array. The operation queue where you add each filterOp isn’t serial, so you could have more than one TiltShiftOperation happening at the same time. This is fine, because their calculations are independent of each other. It’s only when they reach their completionBlock that they compete for access to the same resource: filteredImages. At this point, they go into a serial queue so they can’t interrupt each other.

In real life, you’d probably use a simple serial dispatch queue instead of a serial operation queue.

1 Like

Thank you Audrey! I reviewed the OperationQueue and intro and you did mention that it’s only serial if you set it maxConcurrentOperationCount to 1. Yes, your answer makes sense. Thank you again.

1 Like