Re: Killing a stuck NSThread
Re: Killing a stuck NSThread
- Subject: Re: Killing a stuck NSThread
- From: Douglas Davidson <email@hidden>
- Date: Wed, 26 Apr 2006 14:24:33 -0700
On Apr 26, 2006, at 2:19 PM, Paul Forgey wrote:
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.
CFSocket is the low-level abstraction for using a socket as a run
loop source; NSSocketPort is something different (an NSPort subclass
implemented using CFSocket). Higher-level approaches include
CFStream, NSURLConnection, etc.
If you do use your own separate networking thread and block in
select, you can create an extra local socket (say, via socketpair)
and add it to your select set; then your other threads can use that
socket to tell the networking thread to wake up and respond, e.g. to
a cancellation state.
Douglas Davidson
_______________________________________________
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