Let's say I have an XPC service and two user-visible apps (menu bar item and main app). Both connect to the XPC service.
If both of these app components send a "create Foo" message, how are they dispatched? It's a single process after all, so do they arrive in a sequence or will multiple queues be used?
The XPC service uses Core Data, so I worry about whether I have to create a global queue or ensure thread confinement in any other way.
Any time you use CoreData, XPC or not, in a non-single-threaded executable you need to address threading, either through confinement, main-thread only, or private queue. Since XPC services don't have as well-defined a concept of a main thread (obviously, there is the first thread which will forever be the main thread, but practically speaking...) NSMainQueueConcurrencyType
is probably not useful. I've not seen any indication that any promises are made by XPC about the thread affinity of requests, so I generally proceed under the assumption that the XPC listener's threading management is an implementation detail over which I have no control (until execution transitions into my code). With that in mind, NSConfinementConcurrencyType
looks like a bunch of work. So, if it were me, I'd run with NSPrivateQueueConcurrencyType
.
Even if you empirically observed only one request executing at once, you would be better off assuming that's not guaranteed.