• R
    support for TLS in dynamic-loaded (dlopen) modules · dcd60371
    Rich Felker 提交于
    unlike other implementations, this one reserves memory for new TLS in
    all pre-existing threads at dlopen-time, and dlopen will fail with no
    resources consumed and no new libraries loaded if memory is not
    available. memory is not immediately distributed to running threads;
    that would be too complex and too costly. instead, assurances are made
    that threads needing the new TLS can obtain it in an async-signal-safe
    way from a buffer belonging to the dynamic linker/new module (via
    atomic fetch-and-add based allocator).
    
    I've re-appropriated the lock that was previously used for __synccall
    (synchronizing set*id() syscalls between threads) as a general
    pthread_create lock. it's a "backwards" rwlock where the "read"
    operation is safe atomic modification of the live thread count, which
    multiple threads can perform at the same time, and the "write"
    operation is making sure the count does not increase during an
    operation that depends on it remaining bounded (__synccall or dlopen).
    in static-linked programs that don't use __synccall, this lock is a
    no-op and has no cost.
    dcd60371
libc.h 1.5 KB