iosobjective-cmultithreadingthread-safetycorespotlight

CoreSpotlight default index thread safe


The documentation mentions: https://developer.apple.com/reference/corespotlight/cssearchableindex?language=objc

In batch mode, the client takes responsibility for protecting the private CSSearchableIndex instance from concurrent access from multiple threads; concurrent calls to the index instance have undefined results.

But it doesn't mention what happens in NON batch mode. So let's say I use the default Searchable Index, and indexing takes a non trivial amount of time (1-2 sec). I call

indexSearchableItems:completionHandler:

and while this indexing is still in progress can I call

indexSearchableItems:completionHandler:

again? Or should I protect the default Searchable Index instance from concurrent access myself?


Solution

  • As per the documents if we create a private CSSearchableIndex then its our responsibility to protect it from multiple thread access. The default CSSearchableIndex is thread-safe. I have been using indexSearchableItems:completionHandler: on the defaultSearchableIndex from multiple background threads and never faced a race condition or crash.