-
Re: why are GCD calls nested?
KMT Feb 4, 2019 8:45 AM (in response to maark6000)queues and threads...
See https://stackoverflow.com/questions/34827677/making-sure-im-explaining-nested-gcd-correctly
-
Re: why are GCD calls nested?
john daniel Feb 4, 2019 1:30 PM (in response to maark6000)Some operations can only be executed on the main thread. Other operations may need to access shared data via a serial queue.
-
Re: why are GCD calls nested?
Ken Thomases Feb 4, 2019 2:16 PM (in response to maark6000)If you don't nest that way, then -methodMainThread may start before -methodNotMainThread has completed. The intent is to avoid that, presumably because the former depends on the latter.
-
Re: why are GCD calls nested?
maark6000 Feb 4, 2019 2:21 PM (in response to Ken Thomases)Ah, that makes sense. Okay... thanks!
-
Re: why are GCD calls nested?
john daniel Feb 4, 2019 3:32 PM (in response to Ken Thomases)I bet not, because those are both serial queues.
-
Re: why are GCD calls nested?
Ken Thomases Feb 4, 2019 4:35 PM (in response to john daniel)Whether the queues are serial or concurrent doesn't matter, unless they are the same queue (or target a common serial queue). What matters is that the blocks are dispatched asynchronously. If the calls are not nested, the first block is queued but execution of the code shown immediately continues and queues the second block, too. Both blocks are free to execute from that point on.
-
Re: why are GCD calls nested?
john daniel Feb 4, 2019 6:12 PM (in response to Ken Thomases)If the queues are serial, then when the blocks are free to execute can depend on where they are called from, because they are serial. Given the OP's other posts, I'm pretty sure all this is being executed from the main queue. My goal was trying to explain concurrency, why some operations need to be on the main thread, and how "nesting" is used to achieve that.
But that is really not the issue here. The issue is that the OP is getting confused going back and forth between here and Stack Overflow. The subtle distinctions of when a block is enqueued vs. executed are not all that important right now.
I think I have found the source of the OP's confusion in this case. One of the Stack Overlow threads referenced in the OP's other thread appears to show the "un-nested" code. So, this would be a logical question. Why do one instead of the other? But upon closer inspection, the original Stack Overlow example (near the bottom of stackoverflow.com/questions/7290931/gcd-threads-program-flow-and-ui-updating) is also "nested". It is just poorly indented. It is reasons like this that beginners need to focus on the basics before the subtleties.
-
-
-