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

Add Thread::into_raw and Thread::from_raw functions #109794

Closed
wants to merge 1 commit into from

Conversation

h33p
Copy link

@h33p h33p commented Mar 30, 2023

Allows converting a Thread into a raw pointer for use in futures executors, FFI and other lower level code.

ACP: rust-lang/libs-team#200

I took the liberty to assign thread_pointer_conversion feature flag, but I'm not sure if the functions are the only place I need to add it.

Also I'm unsure whether from_raw needs #[must_use] or not.

@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 30, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@h33p
Copy link
Author

h33p commented Mar 30, 2023

@rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 30, 2023
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
........................................................................................  792/1132
.................................................................................iii....  880/1132
........................................................................................  968/1132
.............................................................................iiiiii..... 1056/1132
.......................F.F..................i...............................
failures:

---- src/thread/mod.rs - thread::Thread::from_raw (line 1346) stdout ----
error[E0658]: use of unstable library feature 'thread_pointer_conversion'
---
   |                                          ^^^^^^^^
   |
   = help: add `#![feature(thread_pointer_conversion)]` to the crate attributes to enable

error[E0277]: `*const ()` cannot be sent between threads safely
    |
    |
9   | let handle = thread::spawn(move || {
    |              ^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
    |
    = help: within `(*const (), *const ())`, the trait `Send` is not implemented for `*const ()`
    = note: required because it appears within the type `(*const (), *const ())`
note: required by a bound in `spawn`
    |
680 |     T: Send + 'static,
    |        ^^^^ required by this bound in `spawn`

---
   |                        ^^^^^^^^^^^^^^^^
   |
   = help: add `#![feature(thread_pointer_conversion)]` to the crate attributes to enable

error[E0369]: binary operation `==` cannot be applied to type `Thread`
   |
   |
20 |     assert_ne!(main_thread, child_thread);
   |     |
   |     Thread
   |     Thread
   |
   |
   = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0369]: binary operation `==` cannot be applied to type `Thread`
   |
21 |     assert_eq!(main_thread, thread::current());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |     |
---
    src/thread/mod.rs - thread::Thread::into_raw (line 1316)

test result: FAILED. 1112 passed; 2 failed; 18 ignored; 0 measured; 0 filtered out; finished in 11.61s

error: doctest failed, to rerun pass `-p std --doc`

@h33p
Copy link
Author

h33p commented Mar 30, 2023

Duplicate of #97524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants