• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Thread not registered mystery under GC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thread not registered mystery under GC


  • Subject: Re: Thread not registered mystery under GC
  • From: Greg Parker <email@hidden>
  • Date: Fri, 5 Nov 2010 14:11:18 -0700

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

  • Follow-Ups:
    • Re: Thread not registered mystery under GC
      • From: Andy O'Meara <email@hidden>
References: 
 >Re: Thread not registered mystery under GC (From: Andy O'Meara <email@hidden>)

  • Prev by Date: Re: Thread not registered mystery under GC
  • Next by Date: Re: Thread not registered mystery under GC
  • Previous by thread: Re: Thread not registered mystery under GC
  • Next by thread: Re: Thread not registered mystery under GC
  • Index(es):
    • Date
    • Thread