-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Open
Labels
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
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.
Metadata
Metadata
Assignees
Labels
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.