Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upThread native name setting #21678
Conversation
rust-highfive
assigned
pcwalton
Jan 27, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
huonw
reviewed
Jan 27, 2015
| pthread_set_name_np(pthread_self(), cname.as_ptr()); | ||
| } | ||
|
|
||
| #[cfg(target_os = "macos")] |
This comment has been minimized.
This comment has been minimized.
huonw
Jan 27, 2015
Member
I think iOS is (somewhat) supported too; does it use pthread_setname_np too?
This comment has been minimized.
This comment has been minimized.
vojtechkral
Jan 27, 2015
Author
Contributor
@huonw It would make sense since the two OSes share the same posix base, but I can't find a direct confirmation... There is a target_os for iOS?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
vojtechkral
Jan 27, 2015
Author
Contributor
Found it: over here it says pthread_setname_np() is available since OS X 10.6 and iOS 3.2
This comment has been minimized.
This comment has been minimized.
vhbit
Jan 27, 2015
Contributor
@vojtechkral @huonw yep, iOS is similar to OS X here, please change it to #[cfg(any(target_os = "macos", target_os = "ios"))]
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
alexcrichton
and unassigned
pcwalton
Jan 27, 2015
alexcrichton
reviewed
Jan 27, 2015
| // because pthread_setname_np() wasn't added until glibc 2.12 | ||
| // PR_SET_NAME since Linux 2.6.9 | ||
| let cname = CString::from_slice(name.as_bytes()); | ||
| prctl(15i32 /* = PR_SET_NAME */, cname.as_ptr() as u64, 0u64, 0u64, 0u64); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
vojtechkral
Jan 28, 2015
Author
Contributor
@alexcrichton Sure, which function though? prctl() or pthread_setname_np()?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 28, 2015
Member
For pthread_setname_np, but largely only because it looks like it's only defined on newer glibc implementations. This is a bit of a nicety, however, so we probably won't lose too much if it's not available.
alexcrichton
reviewed
Jan 27, 2015
| match their_thread.name() { | ||
| Some(thename) => unsafe { imp::set_name(thename.as_slice()); }, | ||
| None => {} | ||
| } |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 27, 2015
Member
Could this be folded into thread_info::set to benefit the main thread as well?
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Updated as requested. I'll try to find someone to test this on BSD / OS X ... |
This comment has been minimized.
This comment has been minimized.
vhbit
commented on src/libstd/sys/unix/thread.rs in 33a3d6d
Jan 28, 2015
|
It should be changed to have |
This comment has been minimized.
This comment has been minimized.
|
@vhbit I just noticed that too :) Note that the "ios" target should probably accompany most of the other |
This comment has been minimized.
This comment has been minimized.
|
Have no BSD but will test it on OS X |
This comment has been minimized.
This comment has been minimized.
|
@vojtechkral usually it is although I'm not fast enough to track all the changes :-) |
This comment has been minimized.
This comment has been minimized.
|
Works fine on OS X |
This comment has been minimized.
This comment has been minimized.
|
@vhbit thanks! |
This comment has been minimized.
This comment has been minimized.
|
@bors try 7e67 |
bors
added a commit
that referenced
this pull request
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Seems to break 64-bit android |
This comment has been minimized.
This comment has been minimized.
|
There was a missing "android" target on the extern, which is weird... I don't understand how it compiled on Android before... edit: It's because the other android cfg test are basically redundant since |
This comment has been minimized.
This comment has been minimized.
|
@bors try 9ee9 |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
vojtechkral commentedJan 27, 2015
Fixes #10302
I really am not sure I'm doing this right, so here goes nothing...
Also testing this isn't easy. I don't have any other *nix boxes besides a Linux one.
Test code:
GDB output on my machine:
(I'm not sure why one of the threads is duplicated, but it does that without my patch too...)