2 Replies
      Latest reply: Dec 27, 2016 6:42 AM by imneo RSS
      imneo Level 1 Level 1 (0 points)

        I have this protocol method in the XPC server:

        - (void)ping:(void (^)(NSString* reply))resultHandler;
        

        Then I connect to the XPC server:

        xpc.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(I_LoginHelperProtocol)]
        _agent = [xpc remoteObjectProxyWithErrorHandler:^(NSError *error) {
          /
                MyLog(@"XPC error: %@", error);
                handler(error);
          }];
        
        
        

        Then I call the ping method (or other methods) on the agent:

        _agent ping:^(NSString *reply) {
                [_appLog log:@"LoginHelper Agent ping reply: %@ in thread %@", reply, [NSThread currentThread]];
            }];
        

        My questions is - is it guaranteed that the reply handler is always dispatched in one single thread, or is it possible for XPC service to spawn a new thread to service the request?

        • Re: Is XPC reply guaranteed to be dispatched in a sole single thread?
          eskimo Apple Staff Apple Staff (7,530 points)

          You’re asking about threads when you should be asking about queues.  NSXPCConnection replies are always delivered on a specific serial queue internal to the connection.  There’s a comment in <Foundation/NSXPCConnection.h> that says as much:

          Each NSXPCConnection instance has a private serial queue. This queue is used when sending messages to reply handlers, interruption handlers, and invalidation handlers.

          Which thread runs blocks posted to that queue is not specified.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"