Re: Acquiring an NSConnection otherwise than by registered name?
Re: Acquiring an NSConnection otherwise than by registered name?
- Subject: Re: Acquiring an NSConnection otherwise than by registered name?
- From: Oleg Krupnov <email@hidden>
- Date: Thu, 30 Sep 2010 14:21:12 +0300
Hi Ken,
I understand that you probably cannot help me any further, but just in
case I am reporting the following, if anyone knows a solution or can
benefit from the information
I have checked the mailing archives and it seems that I am not alone
with the problem that runInNewThread does not necessarily cause the
request to be processed in the new thread. Some folks report that
-removeRunLoop helped them, but my experiments show that
1. -removeRunLoop doesn't seem to have any reproducible effect. At
times it works, other times not.
2. Even two subsequents calls via the same NSConnection (for which
-removeRunLoop: and -runInNewThread was called) are not guaranteed to
be handled in the same server thread. The server seems to freely pick
any idle threads that from the ones that are currently running.
3. What is curious, the #2 also happens if instead of -runInNewThread,
I create a thread manually via [NSThread
detachNewThreadSelector:toTarget:withObject:] and [NSConnection
addRunLoop:]. This is very weird -- the server utilizes any threads
you create!
4. Because server threads are assigned to connection requests so
arbitrary, it seems dangerous to manually quit any thread. It may be
being used by the server at the moment at its discretion. This means
effectively, that there is no way to exit unneeded threads on server,
only to launch new.
I have two assumptions:
1. There is [NSConnection multipleThreadsEnabled] that may be causing
this behavior. Unfortunately, there is no way to turn it off, there is
only -enableMultipleThreads, and by default it is on starting from
10.5. I wished there were disableMultipleThreads to try!
2. Can it happen because all connections on the server share the same
receiving port, which is added to the main run loop?
Thanks,
Oleg.
On Thu, Sep 30, 2010 at 3:04 AM, Ken Thomases <email@hidden> wrote:
> Hi Oleg,
>
> On Sep 29, 2010, at 9:57 AM, Oleg Krupnov wrote:
>
>> I tried -[NSConnection removeRunLoop:[NSRunLoop currentRunLoop]], but
>> it doesn't seem to change anything.
>
> Huh. I don't know what's going on there. You might consider opening a developer technical support incident with Apple to ask them for advice on how to achieve what you want. Those cost money, but probably not as much as your time.
>
>
>> Well, I could live with it, because the server already works as
>> multi-threaded, but the problem is that the new thread that is
>> spawned, is not released if the request is handled in the main thread,
>> when I call -invalidate on the connection. And there does not seem a
>> way to get the thread created by runInNewThread to exit it manually,
>> or is there?
>
> Probably not, but you could re-implement -runInNewThread and make arrangements to terminate the thread on other occasions.
>
> I think that an alternative implementation should just remove the connection from the current run loop and spawn a new thread. The method of the new thread would add the connection to its run loop and run the run loop indefinitely. You could change that to add your own signaling mechanism so that, when signaled, the thread would exit instead of looping through the run loop again.
>
> Regards,
> Ken
>
>
_______________________________________________
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