2024-01-21 02:48:41 +00:00
|
|
|
use std::cell::{Cell, RefCell};
|
2016-06-19 13:58:40 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
2020-11-22 08:08:04 +00:00
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
2016-06-19 13:58:40 +00:00
|
|
|
|
2020-11-22 08:08:04 +00:00
|
|
|
#[test]
|
|
|
|
#[cfg_attr(target_os = "emscripten", ignore)]
|
|
|
|
fn sleep() {
|
2016-06-19 13:58:40 +00:00
|
|
|
let finished = Arc::new(Mutex::new(false));
|
|
|
|
let t_finished = finished.clone();
|
|
|
|
thread::spawn(move || {
|
2020-11-22 08:08:04 +00:00
|
|
|
thread::sleep(Duration::new(u64::MAX, 0));
|
2016-06-19 13:58:40 +00:00
|
|
|
*t_finished.lock().unwrap() = true;
|
|
|
|
});
|
2020-11-22 08:08:04 +00:00
|
|
|
thread::sleep(Duration::from_millis(100));
|
2016-06-19 13:58:40 +00:00
|
|
|
assert_eq!(*finished.lock().unwrap(), false);
|
|
|
|
}
|
2024-01-21 02:48:41 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn thread_local_containing_const_statements() {
|
|
|
|
// This exercises the `const $init:block` cases of the thread_local macro.
|
|
|
|
// Despite overlapping with expression syntax, the `const { ... }` is not
|
|
|
|
// parsed as `$init:expr`.
|
|
|
|
thread_local! {
|
|
|
|
static CELL: Cell<u32> = const {
|
|
|
|
let value = 1;
|
|
|
|
Cell::new(value)
|
|
|
|
};
|
|
|
|
|
|
|
|
static REFCELL: RefCell<u32> = const {
|
|
|
|
let value = 1;
|
|
|
|
RefCell::new(value)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(CELL.get(), 1);
|
|
|
|
assert_eq!(REFCELL.take(), 1);
|
|
|
|
}
|