Re: Killing a stuck NSThread
Re: Killing a stuck NSThread
- Subject: Re: Killing a stuck NSThread
- From: Paul Forgey <email@hidden>
- Date: Wed, 26 Apr 2006 14:19:16 -0700
That wouldn't help if the thread is in the middle of a blocking
system call. Sending a message to a thread requires the thread is
able to receive and then act on it.
Your Cocoa app is event driven. Take advantage of it. Use an
NSSocketPort to do what you want, or if you must use a separate
thread to do I/O at the posix level, use non-blocking sockets in a
select loop. From the select loop, you can poll for a timeout
condition after waiting for a maximum time. But using an
NSSocketPort is so much easier and you won't waste a thread just to
wait for network conditions.
On Apr 26, 2006, at 1:49 PM, Ivan Kourtev wrote:
Why not set up a Distributed Objects connection to a proxy object
in the worker thread. Then you can just tell the proxy object to
terminate its thread.
http://developer.apple.com/documentation/Cocoa/Conceptual/
DistrObjects/index.html
--
ivan
On Apr 26, 2006, at 4:02 PM, Axel Andersson wrote:
On Apr 26, 2006, at 20:56, Dustin Wenz wrote:
I have an application that spawns an NSThread to perform a
blocking network operation. Sometimes the operation takes too
long to execute and needs to be cancelled or killed by the main
thread.
Cancelling a thread is generally very hard to get right, and not
something commonly recommended. Consider communicating that the
other thread should exit via some status variable instead. As
you're working with blocking sockets, look into the mechanisms for
testing socket read/writes with a timeout, so that you can break
out of the network operation every once in a while and check your
status variable. Alternatively, use that timeout itself to
determine when the operation has taken too long.
http://developer.apple.com/documentation/Cocoa/Conceptual/
Multithreading/index.html
http://developer.apple.com/documentation/Darwin/Reference/ManPages/
man2/select.2.html
-- Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden