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

Replace ReentrantMutex by a futex-based one on Linux. #95727

Merged
merged 9 commits into from
Apr 13, 2022
Prev Previous commit
Next Next commit
Initialize thread local with const{}.
  • Loading branch information
m-ou-se committed Apr 12, 2022
commit 43651aa34fd7762058aea6920d2e401561d97076
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/locks/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@ impl ReentrantMutex {
/// This can be used as a non-null usize-sized ID.
pub fn current_thread_unique_ptr() -> usize {
// Use a non-drop type to make sure it's still available during thread destruction.
thread_local! { static X: u8 = 0 }
thread_local! { static X: u8 = const { 0 } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we avoid creating new thread_local!? Since pthread keys number available on some platforms is rather small, it would be beneficial for std to use as few pthread keys as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be nice.

I used the address of the THREAD_INFO thread local in an earlier version, to avoid creating a new one, but that one needs Drop, which makes it inaccessible during thread shutdown. We don't have a good way of getting the address of such a thread local's storage after its destructor ran, since its getter function just returns None after destruction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like LOCAL_PANIC_COUNT meets this requirement, but it's a little weird to use it directly. maybe it would be nice to combine the KEYS of map.rs and LOCAL_PANIC_COUNT into one LOCAL_THREAD_STATE .

X.with(|x| <*const _>::addr(x))
}