I know that i can execute tasks asynchronously with dispatch_async and dispatch_get_global_queue.
But how many threads dispatch_async create? What should i do to execute exactly N (no more, no less) threads with GCD, and performe some tasks on them? After execution of task i need to add new task in released thread, maybe in complitation block of previous task.
Or maybe i can control the count of threds with NSOperationQueue?
I know that it has property maxConcurrentOperationCount, but it control only maximum limit of tasks. So, Can I be sure that NSOperationQueue creates no less than 8 threads, in case when i set maxConcurrentOperationCount = 8 and add 12 operations to the NSOperationQueue?
Thank you very much!
You should look into NSThread. It's the way to go if you need fine grain control over exactly the number of threads you want to have running.
Subclass NSOperation for the tasks you want to do and put them into an NSOperationQueue. You can set the number of concurrent operations on the queue.
NSOperationQueue *q = [[NSOperationQueue alloc] init];
q. maxConcurrentOperationCount = N;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With