Open sjc opened 6 years ago
@sjc I just fixed this upstream in a PR, after encountering the same issue in my project. See https://github.com/apple/swift-corelibs-foundation/pull/1695. Judging by your codebase, the preprocessor logic is a little different wrapping the TSD initializer, but just take out the swift runtime guard and it should work.
Also, just FYI, the TSD does get set by CFRunLoopGet0
. So the "first run" logic should be:
CFRunLoopGetCurrent
CFRunLoopGetCurrent
checks the TSD, which should return NULL
/0CFRunLoopGetCurrent
falls back to the more expensive CFRunLoopGet0
which actually gets a legit run loop, then sets the TSD with itCFRunLoopGetCurrent
find the valid TSD and don't call CFRunLoopGet0
anymoreAt least that's what I could make of it as I was debugging this. Either way, I've tested that the current state of the upstream CF repo gives me a junk address and after my PR, it gives me a valid CFRunLoopRef
that I can use elsewhere.
@copumpkin Thanks for letting us know! I'll take a look at your fix over the weekend.
If you:
CFRunLoopGetCurrent()
on the main thread before callingCFRunLoopGetMain()
, orCFRunLoopGetCurrent()
on any other thread You will be returned a junk address to illegal memory. This value seems always to be0xa0000001f
.This is caused by CF retrieving a junk value from the runloop slot in the pthread thread storage.
No calls to set the runloop thread storage (
TDS
) value appears to be made anywhere in CF's initialization code.