Reputation: 1431
I'm trying to understand queue in iOS; with this code
dispatch_queue_t coda_thread=dispatch_queue_create("coda_thread",NULL);
//UIPROGRESS VIEW
for(i=0;i<=10;i=i+1)
{
dispatch_async(coda_thread,
^{
NSLog(@"CODA_THREAD");
NSLog(@"attendo..");
[NSThread sleepForTimeInterval:10];
dispatch_async(dispatch_get_main_queue(),
^{
NSLog(@"MAIN THREAD");
NSLog(@"aggiorno barra..");
[self.upv setProgress:i/10 animated:YES];
});
});
}
I expected no freeze in GUI because sleep is in coda_thread (and not in main queue where is updated the GUI) queue while setProgress in main queue.. Instead I have freeze in my GUI..why this?
Upvotes: 2
Views: 214
Reputation: 130102
The problem is that a dispatch queue is not a new thread. You have no guarantee that the dispatch queue is actually using a different thread. Combining GCD API with thread API just won't work.
Upvotes: 2