RE: Unscheduling CFReadStream from run loop
RE: Unscheduling CFReadStream from run loop
- Subject: RE: Unscheduling CFReadStream from run loop
- From: "Patrick Lee" <email@hidden>
- Date: Mon, 13 Mar 2006 10:10:24 -0700
- Thread-topic: Unscheduling CFReadStream from run loop
Title: RE: Unscheduling CFReadStream from run loop
I looked at the code and the only place that the stream could be accessed outside the run loop is when it is being unscheduled from the run loop. So I moved the unscheduling code into the stream's callback function, but still no luck. Here is the code for unscheduling:
CFReadStreamClose(m_hCFNetworkReadStream);
CFReadStreamSetClient(m_hCFNetworkReadStream, kCFStreamEventNone, NULL, NULL);
CFReadStreamUnscheduleFromRunLoop(m_hCFNetworkReadStream, m_hRunLoop, kCFRunLoopDefaultMode);
CFRelease(m_hCFNetworkReadStream);
m_hCFNetworkReadStream = NULL;
I copied that from the WWDC2005 ImageClient sample. Am I missing something?
Also, our application is required to query the server very often (every 100 ms). This means that I need to create stream, schedule stream, read data, unschedule stream, delete stream, create next stream, ... - every 100 ms. Is it too fast?
Thanks again for your help.
Patrick
-----Original Message-----
From: Becky Willrich [mailto:email@hidden]
Sent: Wednesday, March 08, 2006 4:07 PM
To: Patrick Lee
Cc: email@hidden
Subject: Re: Unscheduling CFReadStream from run loop
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