If you don't want stuff to operate concurrently in the background, then you need a serial queue. To create a serial GCD queue:
dispatch_queue_t queue = dispatch_queue_create("com.appsdev.project1", 0);
And each time you want to add something to that queue, it's simply:
dispatch_async(queue, ^{
// do your background stuff
dispatch_async(dispatch_get_main_queue(), ^{
// update the UI
});
});
If you want to use NSOperationQueue
it's practically as easy:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
And to add operations to that serial queue:
[queue addOperationWithBlock:^{
// do your stuff
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// update the UI
}];
}];
And in answer to your NSThread
question, I don't see any need for that on the basis of what you've described. Certainly there's no perceptible performance issue.
By the way, is the stuff you're adding to your dispatch/operation queue guaranteed to operating synchronously (i.e. you're not doing geocoding or stuff like that which, itself, operates asynchronously, are you?)? If it operates asynchronously, then additional care must be taken.
By the way, if you only care about the most recent location, using operation queues, you also have to opportunity to cancel other operations that have not yet started by calling:
[queue cancelAllOperations];
The operation in progress will complete first (unless you put in code to test to see if it was canceled), but pending operations that have not yet started can easily be canceled before you initiate a new request based upon the latest location. It just depends upon whether you really want all of the location requests processed serially, or whether you just want to finish the one in progress, clear out the others, and queue a new operation based upon the new location. It just depends upon what your app needs, but frequently you only care about the current location. This can ensure that your queue doesn't get too backlogged.