Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?)

like image 220
Tony Avatar asked Jul 25 '26 17:07

Tony


1 Answers

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.

like image 64
Firoze Lafeer Avatar answered Jul 28 '26 13:07

Firoze Lafeer