问题
now i am trying to understand the concept of gcd. using grand central dispatch how to implement multithreading in my application.i have the idea about the gcd concept but i cant implement the concept to my application.i need a simple example with blocks to understand the multithreading using gcd.please help me...
回答1:
Ok.. The most simple example )
You can write this code in any method. For example
-(void) viewDidLoad {
[super viewDidLoad];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Here your non-main thread.
NSLog (@"Hi, I'm new thread");
dispatch_async(dispatch_get_main_queue(), ^{
//Here you returns to main thread.
NSLog (@"Hi, I'm main thread");
});
});
}
回答2:
Try this, its very clear and easy - http://en.wikipedia.org/wiki/Grand_Central_Dispatch
来源:https://stackoverflow.com/questions/15199342/multithreading-and-grand-central-dispatch-on-ios