Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ThreadId instead of TLS-address in ReentrantLock #124881

Merged
merged 1 commit into from
Jul 18, 2024

Commits on Jul 18, 2024

  1. Update ReentrantLock implementation, add CURRENT_ID thread local.

    This changes `ReentrantLock` to use `ThreadId` for the thread ownership check instead of the address of a thread local. Unlike TLS blocks, `ThreadId` is guaranteed to be unique across the lifetime of the process, so if any thread ever terminates while holding a `ReentrantLockGuard`, no other thread may ever acquire that lock again.
    
    On platforms with 64-bit atomics, this is a very simple change. On other platforms, the approach used is slightly more involved, as explained in the module comment.
    
    This also adds a `CURRENT_ID` thread local in addition to the already existing `CURRENT`. This allows us to access the current `ThreadId` without the relatively heavy machinery used by `thread::current().id()`.
    Sp00ph committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    fe89962 View commit details
    Browse the repository at this point in the history