Skip to content

Tracking Issue for Thread::{into_raw, from_raw} #97523

New issue

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

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

Already on GitHub? # to your account

Open
2 of 4 tasks
ibraheemdev opened this issue May 29, 2022 · 3 comments
Open
2 of 4 tasks

Tracking Issue for Thread::{into_raw, from_raw} #97523

ibraheemdev opened this issue May 29, 2022 · 3 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ibraheemdev
Copy link
Member

ibraheemdev commented May 29, 2022

Feature gate: #![feature(thread_raw)]

This is a tracking issue for Thread::into_raw and Thread::from_raw.

These functions allow conversions between a Thread and a raw pointer, which is useful in concurrent code as it allows storing a Thread in an AtomicPtr.

Public API

// std::thread

impl Thread {
    fn into_raw(self) -> *const ();
    unsafe fn from_raw(ptr: *const ()) -> Thread;    
}

Steps / History

Unresolved Questions

  • Do we want to commit to guaranteeing that Thread can always be represented as a pointer/integer?
@ibraheemdev ibraheemdev added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 29, 2022
@yanchith
Copy link
Contributor

yanchith commented Feb 7, 2025

Not sure If I am missing something, but into_raw requires the thread by value, and that is not always available. E.g. JoinHandle::thread only gives out a shared reference.

How can I unpark a thread for which I just have a JoinHandle?

@ibraheemdev
Copy link
Member Author

ibraheemdev commented Feb 7, 2025

@yanchith Thread is cloneable, but it might make sense to have a as_raw method as well.

@yanchith
Copy link
Contributor

yanchith commented Feb 9, 2025

Yeah, thanks! I didn't notice Thread was Clone. I am perfectly happy with that now.

Thread::as_raw: sure, if it can be designed such that the data inside the Arc inside Thread doesn't get dropped meanwhile. Thread::into_inner leaks the Arc, so that's taken care of.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants