about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/concurrency/threadname.rs
blob: 41cac6459b297180589433fd5bbc4a5955b2b946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::thread;

fn main() {
    // When we have not set the name...
    thread::spawn(|| {
        assert!(thread::current().name().is_none());
    });

    // ... and when we have set it.
    thread::Builder::new()
        .name("childthread".to_string())
        .spawn(move || {
            assert_eq!(thread::current().name().unwrap(), "childthread");
        })
        .unwrap()
        .join()
        .unwrap();

    // Long thread name.
    let long_name = std::iter::once("test_named_thread_truncation")
        .chain(std::iter::repeat(" long").take(100))
        .collect::<String>();
    thread::Builder::new()
        .name(long_name.clone())
        .spawn(move || {
            assert_eq!(thread::current().name().unwrap(), long_name);
        })
        .unwrap()
        .join()
        .unwrap();

    // Also check main thread name.
    assert_eq!(thread::current().name().unwrap(), "main");
}