Tony
Tony

Reputation: 38401

Does NSEnumerationConcurrent guarantee multi-threading?

If you use NSEnumerationConcurrent while enumerating a collection using blocks, does Cocoa guarantee that the block will be executed concurrently? Or does it depend on actually the number of objects that need to be enumerated? Additionally, when the operation is in fact concurrent, how does Cocoa decide how many threads to launch?

EDIT: Additional question

On another note, is enumerating a collection with the NSEnumerationConcurrent option synchronous or asynchronous? In other words, if you have some code below the enumeration code, does it get executed only after all the concurrent enumeration are complete? (Threads join?)

Upvotes: 3

Views: 692

Answers (1)

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

No, NSEnumerationConcurrent does not guarantee that the blocks will execute concurrently.

And, yes, if, for example, you use -[NSArray enumerateObjectsWithOptions:usingBlock:] that call will not return until the enumeration is complete.

The current implementation seems to schedule those blocks on the global normal priority GCD queue if you specify NSEnumerationConcurrent. I'm sure that's not guaranteed to be true always.

Hope that helps.

Upvotes: 5

Related Questions