0
votes

guys,little confused abt dispatch queue and thread, there could be several queues and they dispatch tasks to different thread, if the queue is serial, tasks executed in a line and may be in different, its not a problem. but if we have 2 serial queues,can we manage order of them ?

if we put some Database operations in these 2 queues, the data may be wrong?

2

2 Answers

0
votes

If these two queues serve different functional purposes that merit having separate queues, that's fine, but you'd probably just set up a third queue for database interaction, to which those two would dispatch their database interactions. Let this third queue, a dedicate low-level database queue, coordinate all interaction with the database.

If these two queues are just two random database interaction queues, then one might argue for refactoring the code to consolidate them into one.

-1
votes

Yes, you can manage the order. But not with dispatch_queue. You have to use NSOperationQueue:

NSOperationQueue * queue = [[NSOperationQueue alloc] init];
NSBlockOperation * operation1 = [NSBlockOperation blockOperationWithBlock:^{
        // do something
    }];
[queue addOperation:operation1];

NSBlockOperation * operation2 = [NSBlockOperation blockOperationWithBlock:^{
    // do something
}];

[operation2 addDependency:operation1];
[queue addOperation:operation2];

In this code operation2 will start only when operation1 did complete.