Skip to content

Commit dd81b8c

Browse files
committed
Auto merge of rust-lang#3978 - RalfJung:threadname, r=RalfJung
pthread-threadname: ensure we can see the name set via the Rust API
2 parents 8bb356c + 5db0e40 commit dd81b8c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ fn main() {
6565
}
6666
}
6767

68+
// Set name via Rust API, get it via pthreads.
69+
let long_name2 = long_name.clone();
70+
thread::Builder::new()
71+
.name(long_name.clone())
72+
.spawn(move || {
73+
let mut buf = vec![0u8; long_name2.len() + 1];
74+
assert_eq!(get_thread_name(&mut buf), 0);
75+
let cstr = CStr::from_bytes_until_nul(&buf).unwrap();
76+
let truncated_name = &long_name2[..long_name2.len().min(MAX_THREAD_NAME_LEN - 1)];
77+
assert_eq!(cstr.to_bytes(), truncated_name.as_bytes());
78+
})
79+
.unwrap()
80+
.join()
81+
.unwrap();
82+
83+
// Set name via pthread and get it again (short name).
6884
thread::Builder::new()
6985
.spawn(move || {
7086
// Set short thread name.
@@ -130,6 +146,7 @@ fn main() {
130146
.join()
131147
.unwrap();
132148

149+
// Set name via pthread and get it again (long name).
133150
thread::Builder::new()
134151
.spawn(move || {
135152
// Set full thread name.

0 commit comments

Comments
 (0)