Multithreading and Grand Central Dispatch on iOS [closed]

孤者浪人 提交于 2019-12-05 00:31:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!