Re: Unscheduling CFReadStream from run loop
Re: Unscheduling CFReadStream from run loop
- Subject: Re: Unscheduling CFReadStream from run loop
- From: Becky Willrich <email@hidden>
- Date: Wed, 8 Mar 2006 15:07:17 -0800
Do you always unschedule from the thread where the stream is
scheduled? Once the stream is scheduled on a given run loop, it's not
safe to manipulate that stream from anywhere but the run loop where
it's scheduled - the stream could be in the middle of processing an
event on the scheduled thread, while from another thread you call in
and manipulate the stream, and now you're accessing the same stream
from two threads....
Hope that helps - REW
On Mar 8, 2006, at 2:55 PM, Patrick Lee wrote:
Hi,
I'm using CFReadStream to implement HTTP communication in a client/
server application. For various reasons, I create a thread using BSD
call pthread_create() and call CFRunLoop() to start the run loop. On
the other thread, I create a CFReadStream object, set the callback
functions, and schedule the read stream into the run loop. Client
program is required to update server continuously and this means
that the program needs to keep scheduling and unscheduling read
streams from the run loop.
The way the read stream is unscheduled from the run loop is:
CFReadStreamClose(m_hCFNetworkReadStream);
CFReadStreamSetClient(m_hCFNetworkReadStream,
kCFStreamEventNone, NULL, NULL);
CFReadStreamUnscheduleFromRunLoop(m_hCFNetworkReadStream,
m_hRunLoop, kCFRunLoopDefaultMode);
CFRelease(m_hCFNetworkReadStream);
m_hCFNetworkReadStream = NULL;
The problem is that occasionally (very often actually) the program
crashes while unscheduling read stream and the call stack is:
CFGetTypeID
_CFTypeUnscheduleFromMultipleRunLoops
AddressLookupPerform
_CFRunLoopDoSource
_CFRunLoopRun
CFRunLoopRunSpecific
CFRunLoopRun
, then myprogram's Run()
I've been struggled for quite a while. Please help.
Patrick
_______________________________________________
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