i have four operations to be done as follows
- start actvityindicator.
- do some caclulations. (in bg thread)
- save the results in xml .(in bg thread)
- stop the actvityindicator.
Now I am doing these operations in GCD as follows.
[self showAlert];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self calculateValues];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[utility createXMLWithName:name];
dispatch_sync(dispatch_get_main_queue(), ^{
[self hideAlert];
});
});
});
I want to confirm is this the right way to do this in GCD? I need the task 2 and 3 in bg and also task 3 should happen only after task 2 finishes. For that i put the task 2 and 3 in separate queues.
i think it will work but i am not sure this is the best approach.
i have posted some article about concurrency programing you might find it interesting for you question , you could have a look. concurrency programming in objective C
in general if you would like to be sure you run your thread only after other thread is finish his work you can use:
[NSObject performSelector: onThread: withObject: waintUntilDone:YES]; .
(you could use NSOperation but it seems like overhead for what you need )
but in your case i don’t really understand why you need the second background thread for task 3, if you want to run it only when task 2 finish.
couldn’t you just right task 2 and then 3.