Skip to content

Commit

Permalink
Auto merge of #3978 - RalfJung:threadname, r=RalfJung
Browse files Browse the repository at this point in the history
pthread-threadname: ensure we can see the name set via the Rust API
  • Loading branch information
bors committed Oct 18, 2024
2 parents ca43b55 + e64406b commit 2a2aa27
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 2a2aa27

Please sign in to comment.