Re: nss_ldap broken

From: Daniel Eischen (eischen_at_vigrid.com)
Date: 03/30/04

  • Next message: Jacques A. Vidrine: "Re: nss_ldap broken"
    Date: Mon, 29 Mar 2004 22:31:56 -0500 (EST)
    To: "Jacques A. Vidrine" <nectar@FreeBSD.org>
    
    

    On Mon, 29 Mar 2004, Jacques A. Vidrine wrote:

    > On Fri, Mar 26, 2004 at 05:51:02PM -0500, Daniel Eischen wrote:
    > > I think I made a comment about how you should always
    > > prefix _pthread_foo() calls with 'if (__isthreaded)'.
    >
    > Yes, I'm sure you did. My recollection was that it was an
    > optimization only, but it seems either I misunderstood or my
    > recollection is poor (or both) :-)

    I had no idea that libpthread would be loaded then unloaded.

    > > When the thread libraries are initialized, then overrwrite
    > > the function pointers in libc's thread jumptable. If you
    > > unload the library, libc still retains those pointers.
    >
    > OK, so we guard calls to threading routines with __isthreaded. (Patch
    > below.) Uglifies things a bit, but I can deal. Maybe some day we'll
    > rewrite reentrant.h so that it doesn't lose the return code (they
    > should all be like mutex_trylock?).
    >
    >
    > So, if I understand correctly:
    >
    > (1) __isthreaded starts out 0
    > (2) When a threading library is loaded (by any cause? DT_NEEDED?
    > dlopen RTLD_GLOBAL? dlopen RTLD_LOCAL?), __isthreaded is set
    > to 1

    No, __isthreaded is only set to 1 (non-zero) when the first
    thread (other than main) is created. But the library is
    auto-initialized and that's when libc's jump table is
    filled.

    > (3) When a threading library is unloaded, __isthreaded is reset to 0

    No, once threaded always threaded. There's really no going
    back.

    > Only, I don't immediately see where (3) happens...
    >
    > Sean, could you report how this patch works for you? Hmm, actually, it
    > looks almost identical to what you posted :-) Is there a reason that
    > you stored the value of `__isthreaded' in a local variable? Did that
    > make a difference for your case?

    I'm unsure how nss_ldap was built to depend on libpthread (or
    any threads library). I built it from ports and 'ldd' didn't
    report any dependency on a threads library.

    An example of how to build a library that is thread-safe
    but doesn't bring in the threads library is libgcc. It uses
    weak references (not definitions, like you see in our libc
    and libpthread) to the necessary locking functions and
    pthread_create. For instance:

            #pragma weak pthread_create
            #pragma weak pthread_mutex_lock
            #pragma weak pthread_mutex_unlock
            ...

            static void
            foo(void)
            {
                    ...
                    if (pthread_create != NULL) {
                            pthread_mutex_lock(&foo_lock);
                            ...
                            pthread_mutex_unlock(&foo_lock);
                    }
                    ...
            }

    By making the pthread_* references weak, you don't need to be linked
    to the threads library; they will be NULL if it is not present.
    But if an application is linked to the threads library, then
    those references won't be NULL. There may be a little more
    fu to it, but that's the general idea.

    -- 
    Dan Eischen
    _______________________________________________
    freebsd-current@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-current
    To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
    

  • Next message: Jacques A. Vidrine: "Re: nss_ldap broken"

    Relevant Pages

    • Re: nss_ldap broken
      ... but it seems either I misunderstood or my ... > I had no idea that libpthread would be loaded then unloaded. ... I built it from ports and 'ldd' didn't ... > weak references (not definitions, like you see in our libc ...
      (freebsd-current)
    • Re: Suzuki LS650 - only 30hp???
      ... What happened was a lot of bikes that could have ... built to 100bhp. ... of the 100hp limit was actually a memory of the 125 hp limit. ... The references to a 100hp limit that you cited jibe ...
      (rec.motorcycles)
    • Re: Can someone explain this weakref behavior?
      ... >> is more robust than simply incrementing and decrementing class variables ... >> immediately deleting the weak reference as soon as all references to the ... >> behavior of weak references? ... refcount of zero. ...
      (comp.lang.python)
    • A re-announce on GCs defects
      ... The need for weak reference makes the destruction delay logically incorrect. ... Weak references refer to references who do ... When all strong references to a target go out of their lifetime, ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Copy object with .Net?
      ... To create a shallow copy of your object (i.e. just value fields, ... references to other objects will be the same), use the MemberwiseClone ... (built into objects) ...
      (microsoft.public.dotnet.languages.vb)

    Loading