[x86_64-fortanix-unknown-sgx] Failing stdlib threading test
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
After PR-144465 got merged, the test named test_named_thread (in library/src/std/thread/tests.rs) started failing for sgx target. I managed to find that, the breaking change is ThreadInit refactoring. For some reason, the call to set_current in ThreadInit::init looks ineffective. When i move set_current & set_name calls from ThreadInit::init to the rust_start closure (just like pre-PR), the test passes.
Here the changes that fixes this failure:
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 983d189b070..0565c4ba98f 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -229,14 +229,15 @@ pub fn init(self: Box<Self>) -> Box<dyn FnOnce() + Send> {
// so that it may call std::thread::current() in its implementation. This is also
// why we take Box<Self>, to ensure the Box is not destroyed until after this point.
// Cloning the handle does not invoke the global allocator, it is an Arc.
- if let Err(_thread) = set_current(self.handle.clone()) {
- // The current thread should not have set yet. Use an abort to save binary size (see #123356).
- rtabort!("current thread handle already set during thread spawn");
- }
+ // if let Err(_thread) = set_current(self.handle.clone()) {
+ // // The current thread should not have set yet. Use an abort to save binary size (see #123356).
+ // rtabort!("current thread handle already set during thread spawn");
+ // }
- if let Some(name) = self.handle.cname() {
- imp::set_name(name);
- }
+ // if let Some(name) = self.handle.cname() {
+ // imp::set_name(name);
+ // }
+ let _ = self.handle;
self.rust_start
}
@@ -572,10 +573,21 @@ fn drop(&mut self) {
}
let f = MaybeDangling::new(f);
+ let their_thread = thread.clone();
// The entrypoint of the Rust thread, after platform-specific thread
// initialization is done.
let rust_start = move || {
+
+ if let Err(_thread) = set_current(their_thread.clone()) {
+ // The current thread should not have set yet. Use an abort to save binary size (see #123356).
+ rtabort!("current thread handle already set during thread spawn");
+ }
+
+ if let Some(name) = their_thread.cname() {
+ imp::set_name(name);
+ }
+
let f = f.into_inner();
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
crate::sys::backtrace::__rust_begin_short_backtrace(|| hooks.run());
The PR-144465 is in beta branch now.
Thank you.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with library/std/src/thread/mod.rs and the test_named_thread test in library/src/std/thread/tests.rs; compare ThreadInit::init with the rust_start closure for the x86_64-fortanix-unknown-sgx target. Run the failing stdlib threading test on the SGX target and confirm that named-thread behavior passes without regressing other thread tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100