• Ben Maurer's avatar
    SIOF-proof thread local · 2bebe62f
    Ben Maurer authored
    Summary: Right now ThreadLocal & friends don't operate correctly when used as a
    static variable (which is the idiomatic way to use them). The TLS id is
    allocated in the static constructor so anybody who uses the ID prior to
    first use would use an invalid ID. This makes ThreadLocal unusable for core
    code such as per-thread reference counting.
    
    This diff allocates the ID on first use. By making the invalid ID maxint we
    avoid adding any extra branches in the fast path. We can then make the
    constructor a constexpr meaning that initialization will happen prior to
    any code running.
    
    Reviewed By: @meyering
    
    Differential Revision: D2457989
    
    fb-gh-sync-id: 21d0c0d00c638fbbd36148d14d4c891f66f83706
    2bebe62f
ThreadLocal.h 9.65 KB