Re: CFHTTPMessage and thread safety
Re: CFHTTPMessage and thread safety
- Subject: Re: CFHTTPMessage and thread safety
- From: Mark Pauley <email@hidden>
- Date: Fri, 29 Aug 2008 12:22:42 -0700
Could you explain what you mean by this? Were you running into issues
with persistent connections that were each used from a single thread?
Or were you trying to set the persistent connection bit of a
connection scheduled on one thread from another thread?
As Quinn said, I would expect that CFHTTPReadStreamAPI is perfectly
thread-safe as long as you're locking around access to individual
streams or only using a given stream on a single thread. Remember
that if you've got a stream scheduled on multiple RunLoops that you'll
likely have to lock around the stream callback as well, since once you
call CFReadStreamRead, your stream can get signalled with more events,
which may cause you to reenter your stream callback (most people don't
expect that sort of behavior).
In particular, it should be absolutely fine to: create a stream on one
thread and schedule it on another, or create a stream on one thread
and schedule it on multiple threads, etc. Just make sure you do all
of your property setting before you call open, or you may need to
lock. You are in charge of locking around mutations, and you
absolutely must lock around mutations of your client context. We have
tests that use the API in the following fashion: spawn a bunch of
threads, each thread creates a message / http stream and sets the
Persistent Connection property on its stream. Then we schedule on the
current RunLoop, run the current RunLoop and handle the callbacks,
unschedule and join the thread when the download is finished. What is
your usage pattern?
On Aug 29, 2008, at 10:21 AM, Bertrand Landry-Hetu wrote:
I used to have many threads talking to one server using CFHTTPMessage
and everything was fine until I had to turn on
kCFStreamPropertyHTTPAttemptPersistentConnection, which turned out to
not be thread safe (at least from what I can see in the 10.4 source
code that was made public).
Nowadays, to be really safe, I keep all my CFNetwork traffic in the
same background thread and I haven't had any issues since.
2008/8/28 Mark Thomas <email@hidden>:
Hi All,
Was wondering if anybody could advise on how thread safe the
CFHTTPMessage
/ CFReadStream API's where ? (I am aware that I can use a runloop
call
function, but I'm working on keep the main thread to a minimum)
Thanks
Mark.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog 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.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_Mark
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden