summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/sgx/waitqueue/spin_mutex/tests.rs
blob: 4c5994bea61f723ec6c52078afd13cde2990a7fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#![allow(deprecated)]

use super::*;
use crate::sync::Arc;
use crate::thread;
use crate::time::Duration;

#[test]
fn sleep() {
    let mutex = Arc::new(SpinMutex::<i32>::default());
    let mutex2 = mutex.clone();
    let guard = mutex.lock();
    let t1 = thread::spawn(move || {
        *mutex2.lock() = 1;
    });

    thread::sleep(Duration::from_millis(50));

    assert_eq!(*guard, 0);
    drop(guard);
    t1.join().unwrap();
    assert_eq!(*mutex.lock(), 1);
}