Closed blakewatters closed 10 years ago
Work rewiring the internals to use GCD and a dedicated NSThread
+ NSRunLoop
is on the @layerhq fork: https://github.com/layerhq/CocoaSPDY/pull/2
This problem is actually easily solved by utilizing CFRunLoopPerformBlock
to ensure closing of the SPDY socket takes place on the NSURLConnection thread.
We also have an implementation of CocoaSPDY that runs its socket and streams on a dispatch queue instead of run loops but it has never felt as solid as the runloop approach.
Do you have an example of the runloop implementation that uses CFRunLoopPerformBlock
? Also, do you have concrete examples of why the GCD approach is less solid, or is it just a gut feeling?
Ah, I see it in SPDYSession.m's close method in https://github.com/twitter/CocoaSPDY/pull/59.
The branch that uses GCD exhibits a strange stalling behavior that we have not been able to pin down. The changes also required trampolining from basically every public method back onto the dispatch queue in order to guarantee thread safety so its a considerably heavier change than the perform block change.
I wanted to open up a discussion about the approach to threading utilized in the library. CocoaSPDY is presently totally reliant on the socket being interacted with only through the
NSURLConnectionLoader
thread to guarantee its safety.This has presented a number of challenges:
NSURLProtocol
interface.In general I find GCD much easier to work with and reason about than runloops — particularly on threads I can’t access at will.
I have a patch set in development that introduced a GCD queue into the
SPDYSocket
class to ensure thread safety. This eliminates the need forCHECK_THREAD_SAFETY
macros by providing strong guarantees of thread safety. Is this work you would consider merging?