1

In my App I need to run more than 300 threads asynchronously [Each thread dies within 500ms] . In Android I write an ayncTask class and run my code inside of it. How Can we do in iOS, I need a class not a function.

Please Provide any example, tutorial or documentation. It will be a great help.

AMI amitekh
  • 198
  • 3
  • 16
  • `NSThread`? BTW, 300 threads is total overkill on a 4 or 8 core device. You may wish to check into GCD and `NSOperationQueue`. – Avi Jul 19 '16 at 06:54
  • 1
    Please provide any example or tutorial or article if available. Thats a great help – AMI amitekh Jul 19 '16 at 06:55

1 Answers1

3

I would use GCD for this purpose, please refer to this tutorial or to apple documentation : https://www.raywenderlich.com/60749/grand-central-dispatch-in-depth-part-1

This would optimize the number of threads according to the device capabilibilities and eliminate unnecessary thread allocations. You would need Concurrent queue. The simplest(not the most optimized way) is:

 dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     // do your task here
  });

For more information check the previously mentioned article.

l.vasilev
  • 926
  • 2
  • 10
  • 23
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/13051275) – NSNoob Jul 20 '16 at 11:45
  • You are right I will edit it in a minute with the simplest solution. – l.vasilev Jul 20 '16 at 12:02