gh-114271: Make `thread._rlock` thread-safe in free-threaded builds by mpage · Pull Request #115102 · python/cpython

@mpage

The ID of the owning thread (`rlock_owner`)  may be accessed by
multiple threads without holding the underlying lock; relaxed
atomics are used in place of the previous loads/stores.

The number of times that the lock has been acquired (`rlock_count`)
is only ever accessed by the thread that holds the lock; we do not
need to use atomics to access it.

The embedded lock (`rlock_lock`) is already thread-safe.

@bedevere-app bot mentioned this pull request

Feb 6, 2024

@mpage mpage marked this pull request as ready for review

February 6, 2024 21:06

colesbury

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request

Mar 4, 2024
…ilds (python#115102)

The ID of the owning thread (`rlock_owner`) may be accessed by
multiple threads without holding the underlying lock; relaxed
atomics are used in place of the previous loads/stores.

The number of times that the lock has been acquired (`rlock_count`)
is only ever accessed by the thread that holds the lock; we do not
need to use atomics to access it.

diegorusso pushed a commit to diegorusso/cpython that referenced this pull request

Apr 17, 2024
…ilds (python#115102)

The ID of the owning thread (`rlock_owner`) may be accessed by
multiple threads without holding the underlying lock; relaxed
atomics are used in place of the previous loads/stores.

The number of times that the lock has been acquired (`rlock_count`)
is only ever accessed by the thread that holds the lock; we do not
need to use atomics to access it.

LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull request

Jan 22, 2025
…ilds (python#115102)

The ID of the owning thread (`rlock_owner`) may be accessed by
multiple threads without holding the underlying lock; relaxed
atomics are used in place of the previous loads/stores.

The number of times that the lock has been acquired (`rlock_count`)
is only ever accessed by the thread that holds the lock; we do not
need to use atomics to access it.