synchronization, without the ability to open threads: Dispatch_sync
Asynchronous, with the ability to open threads: Dispatch_async
Parallel queues: Multiple tasks can be executed concurrently
Serial queue: Once a task is finished, the next task is executed
An allusion to a golden code:
#define Zhglobalqueue dispatch_get_global_queue (dispatch_queue_priority_default, 0)
#define Zhmainqueue Dispatch_get_main_queue ()
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
Dispatch_async (Zhglobalqueue, ^{
1. Child threads
nsstring* urlstr = @ "";
Nsurl *url = [Nsurl urlwithstring:urlstr];
NSData *data = [NSData Datawithcontentsofurl:url];
UIImage *image = [UIImage imagewithdata:data];
2. Set the picture back to the main thread
Dispatch_async (Zhmainqueue, ^{
[Self.imageview Setimage:image];
});
});
}
Those words in the iOS thread