help-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inter-thread communication with NSPort


From: Fred Kiefer
Subject: Re: Inter-thread communication with NSPort
Date: Sat, 03 Feb 2007 15:29:12 +0100
User-agent: Thunderbird 1.5.0.9 (X11/20060911)

Richard Frith-Macdonald schrieb:
> 
> On 3 Feb 2007, at 07:32, Tima wrote:
> 
>> I'm trying to make a client-server application in GNUstep.
>> Right now it seems that the best way to do the client is to
>> make it a two-threaded application, with a main thread processing
>> GUI events and a "worker" thread waiting and reading messages
>> from socket-related NSInputStream.
>>
>> I want the worker thread to notify the main one when the message is
>> ready.
>> After reading Apple documentation for some time I got an impression
>> that I need to send message to main thread's NSPort, it will be delivered
>> via -handlePortMessage: method of the port's delegate.
>>
>> First of all, is it really the intended way to do communication
>> between threads?
> 
> No ... you should use distributed objects over an NSConnection.
> While in theory you can work with ports directly, it's certainly not
> recommended and is considerably more complex for you to code than using
> NSConnections.
> 
> However, fort the one-way communication you describe, probably the
> simplest and most efficient option would be for your worker thread to
> use the -performSelectorOnMainThread:withObject:waitUntilDone:modes:
> method of NSObject.
> 
> PS. I think you probably have the ports the wrong way round in your port
> message.
> 

While I fully agree with your proposed replacements, I am not sure, if
your analysis of the problem is correct. To me it looks like sending and
receiving port have been specified correctly.
As this is quite a nice little example it would be great to understand
what goes wrong here.

Cheers,
Fred




reply via email to

[Prev in Thread] Current Thread [Next in Thread]