Skip to content

pthread-threadname: ensure we can see the name set via the Rust API #3978

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

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/pass-dep/libc/pthread-threadname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ fn main() {
}
}

// Set name via Rust API, get it via pthreads.
let long_name2 = long_name.clone();
thread::Builder::new()
.name(long_name.clone())
.spawn(move || {
let mut buf = vec![0u8; long_name2.len() + 1];
assert_eq!(get_thread_name(&mut buf), 0);
let cstr = CStr::from_bytes_until_nul(&buf).unwrap();
let truncated_name = &long_name2[..long_name2.len().min(MAX_THREAD_NAME_LEN - 1)];
assert_eq!(cstr.to_bytes(), truncated_name.as_bytes());
})
.unwrap()
.join()
.unwrap();

// Set name via pthread and get it again (short name).
thread::Builder::new()
.spawn(move || {
// Set short thread name.
Expand Down Expand Up @@ -130,6 +146,7 @@ fn main() {
.join()
.unwrap();

// Set name via pthread and get it again (long name).
thread::Builder::new()
.spawn(move || {
// Set full thread name.
Expand Down