about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass-dep/libc/gettid.rs
blob: 51f1a5ed708982c065dd57c65a75d9a9b167009c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//@only-target: linux
//@revisions: with_isolation without_isolation
//@[without_isolation] compile-flags: -Zmiri-disable-isolation

use std::thread;

use libc::{getpid, gettid};

fn main() {
    thread::spawn(|| {
        // Test that in isolation mode a deterministic value will be returned.
        // The value 1001 is not important, we only care that whatever the value
        // is, won't change from execution to execution.
        #[cfg(with_isolation)]
        assert_eq!(unsafe { gettid() }, 1001);

        assert_ne!(unsafe { gettid() }, unsafe { getpid() });
    });

    // Test that the thread ID of the main thread is the same as the process
    // ID.
    assert_eq!(unsafe { gettid() }, unsafe { getpid() });
}