DO, NSConnection, NSThreads, NSRunLoops, and method running/stopping
DO, NSConnection, NSThreads, NSRunLoops, and method running/stopping
- Subject: DO, NSConnection, NSThreads, NSRunLoops, and method running/stopping
- From: Esteban <email@hidden>
- Date: Thu, 20 Dec 2001 23:02:25 -0800
Hi,
I haven't seen this discussed in the archives, and its been bugging me.
I am developing a Multithreaded application using DO. What i need to do
is have a spun off thread send data and another receive it. The
functionality is pretty exclusive.
My plan is to have the receiveThread run a while loop and keep listening
to a socket for data. It has its locks of course, and some checking as
i'm using this same socket in my sendThread for sending out data.
Now, I would like to have the receiveThread keep running in a while loop
until I know that i will not need it any more. My logic is that I can
set up a static NSMutableDictionary that will contain some information
as to whether i need to stop the receive method in the receiveThread and
have this NSMutableDictionary (call it threadIDDictionary) be updated by
a method +stopMethodInThread:(NSString*)threadID.
The while loop in the receive method in the receiveThread will check to
see if the value for the thread's threadID dictates that the method
should stop going through the while loop.
The reason for all of this is that I don't want to deal with having to
call the receivethread's receive method everytime i get data, but
instead have it send data over to the main thread for processing and
continue on until the main thread calls stopMethodInThread....
Now I have a couple of questions. When invalidating the NSConnection,
does that automatically stop any running method? Does the invalidation
call [NSThread exit]? And if so is there a way I can clean up anything
left uncleaned within the space of the running method once invalidation
of NSConnection occurs? In otherwords, is there a way to set up a exit
handler for the thread?
Finally, the sendThread is very simple calling only a send method, which
exits after it sends data, although I've though of it also having a
while loop and querying the main thread for new data, which would mean
the main thread would keep generating and adding to an array and the
sendThread consuming that array.
Thanks for any help :) Code snippets are welcomed, too
-Esteban Uribe