I want to know if blocks in c / coc开发者_Python百科oa run on a seperate thread to the main thread. Would they be useful for executing computationally expensive code while leaving the UI responsive?
Blocks are just snippets of code bundled up into a callable object. How they run is entirely up to the code that calls it.
Running blocks on a separate thread is not only possible, but is precisely the reason the blocks concept was introduced. It exists to support Grand Central Dispatch, which hides a lot of the complexity of concurrent programming behind a task-oriented model.
They don't have to run on another thread, but they can. You can schedule them on NSOperationQueues or GCD queues, and those queues can be drained by background threads.
And yes, this can be a useful construct to help you get time consuming work off the main thread. But that's not all that blocks are useful for, and conversely you can do background processing with or without blocks.
You can use GCD to schedule blocks for issuing on other threads. The two were introduced together, so any discussion of the one usually mentions the other. However, blocks are not in themselves inherently a multithreading mechanism.
精彩评论