Re: Accessing NSDistantObject from different threads concurrently
Re: Accessing NSDistantObject from different threads concurrently
- Subject: Re: Accessing NSDistantObject from different threads concurrently
- From: Oleg Krupnov <email@hidden>
- Date: Thu, 23 Sep 2010 20:21:04 +0300
So, how do I implement multiple threads in the server process?
I have the following idea:
Vend many objects. First, vend a root object in the server process and
then have it create new server threads by client request and return a
connection name to the client. The new server thread creates a
connection with the above name, and through it vends its per-thread
object, and then launches its run loop to listen to the connection.
Is this a valid approach?
What is nice about it, is that there is no trouble with
synchronization. The client thread first attempts to open the
connection by the name and simply blocks until it gets it without
blocking the main server thread nor the main client thread. However,
as I understand, these named connections are visible system-wide, so I
wonder if having too many named connections is expensive for the
system, isn't it?
I would appreciate comments or suggestions of other designs. Am I on
the right path at all?
Thanks,
Oleg.
On Mon, Sep 20, 2010 at 8:32 PM, Oleg Krupnov <email@hidden> wrote:
> Thanks, Kyle
>
>> Multithreading is not a prerequisite for serving multiple clients. Depending on what your server's doing, sticking with NSRunLoop-based multiplexing might be a lot easier.
>
> The server's job is associated with slow devices, such as disk, but
> are quite lengthy in time. In your scenario, all client threads will
> be unnecessarily waiting for the server to complete the current job,
> while there is still a lot of CPU time to run the other jobs
> concurrently.
>
>> The NSConnection documentation has a bunch of methods for dealing with multiple threads.
>
> Maybe you're right, but I haven't found examples. A pointer would be
> appreciated. Am I correct assuming that by default there is only one
> thread in the server process, and if multiple threads are trying to
> access the proxy, all but one will be blocked?
>
>> In your case, though, it sounds like you only want to vend one object through which all your clients communicate. Even if that communication is achieved by asking the vended object for another object with which to communicate.
>
> I don't mind to vend only a single object, through which to ask for
> the other object to actually communicate with clients. I've been
> thinking about it myself. The problem is how to spawn a new thread for
> each such object in the server process and make it listen to all
> incoming requests from the corresponding client.
>
> Thanks,
>
> Oleg.
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden