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...
现在我想了解gcd的概念。使用大中心调度如何在我的应用程序中实现多线程。我有关于gcd概念的想法但我无法将这个概念实现到我的应用程序。我需要一个简单的例子用块来理解多线程使用gcd.please帮助我...
2 个解决方案
#1
18
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
1
Try this, its very clear and easy - http://en.wikipedia.org/wiki/Grand_Central_Dispatch
试试这个,非常简单明了 - http://en.wikipedia.org/wiki/Grand_Central_Dispatch
#1
18
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
1
Try this, its very clear and easy - http://en.wikipedia.org/wiki/Grand_Central_Dispatch
试试这个,非常简单明了 - http://en.wikipedia.org/wiki/Grand_Central_Dispatch