Re: Thread not registered mystery under GC
Re: Thread not registered mystery under GC
- Subject: Re: Thread not registered mystery under GC
- From: Andy O'Meara <email@hidden>
- Date: Fri, 5 Nov 2010 16:17:28 -0500
Perfect, Greg, thanks!!
On Nov 5, 2010, at 4:11 PM, Greg Parker wrote:
> On Nov 5, 2010, at 2:01 PM, Andy O'Meara wrote:
>> I'm having an issue with using objc_registerThreadWithCollector() under earlier versions of OS X. 10.4 cancels my app load because it can't resolve that symbol at dynamic link time, so I'm trying to figure out how to fetch the symbol address by name. Of course, if the symbol isn't present then it won't be called. I have to be able to build and ship a binary that works under 10.4 so I can't just make the min OS version 10.6 at build time.
>>
>> Can you suggest or point me toward a snippet that demonstrates a Cocoa-resident symbol lookup?
>
> It's supposed to work like this using weak symbol import:
>
> if (objc_registerThreadWithCollector) {
> objc_registerThreadWithCollector();
> } else {
> // do something else
> }
>
> but (1) objc_registerThreadWithCollector is missing the required availability declaration in the current SDKs, and (2) there's a compiler "optimization" that assumes the `if` condition is always true.
>
> The alternative is dynamic lookup like this:
>
> #include <dlfcn.h>
> void (*registerThreadWithCollector_fn)(void);
> registerThreadWithCollector_fn = (void(*)(void)) dlsym(RTLD_NEXT, "objc_registerThreadWithCollector");
> if (registerThreadWithCollector_fn) {
> (*registerThreadWithCollector_fn)();
> } else {
> // do something else
> }
>
> The lookup can be slow, so you should do it once and save the result.
>
>
> --
> Greg Parker email@hidden Runtime Wrangler
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden