Re: Concurrent tasks are getting hung up
Re: Concurrent tasks are getting hung up
- Subject: Re: Concurrent tasks are getting hung up
- From: Jim Crate <email@hidden>
- Date: Fri, 10 Oct 2014 11:27:42 -0400
On Oct 10, 2014, at 11:00 AM, Kyle Sluder <email@hidden> wrote:
>> On Oct 10, 2014, at 6:42 AM, Steve Mills <email@hidden> wrote:
>>
>> I've only created one NSOperationQueue and added many NSInvocationOperation to it.
>
> NSOperationQueue works by dispatching your blocks to the global async GCD queue. If you send a thousand blocks to be async processed at once, GCD will keep spinning up threads to try to service them until it exhausts the thread limit and your process deadlocks.
>
> It sucks, but you have to be judicious in the number of blocks you submit to the global queue. Set a max operation count on your NSOperationQueue.
I ran into the same problem in my first foray into using NSOperationQueue. When adding several hundred block operations to the queue, it pretty much choked trying to run all several hundred at once. Now, when I create an NSOperationQueue for what could be more than a few operations, I always use:
myQueue.maxConcurrentOperationCount = [[NSProcessInfo processInfo] processorCount];
The processorCount is actually logical core count, so on my 4-core i7 it returns 8.
Jim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden