#[macro_use]
extern crate crossbeam_channel;
extern crate crossbeam_utils;
use std::thread;
use std::time::Duration;
use crossbeam_channel::unbounded;
use crossbeam_utils::thread::scope;
fn ms(ms: u64) -> Duration {
Duration::from_millis(ms)
}
#[test]
#[cfg_attr(target_os = "macos", ignore = "TLS is destroyed too early on macOS")]
fn use_while_exiting() {
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
let (_s, r) = unbounded::<()>();
select! {
recv(r) -> _ => {}
default(ms(100)) => {}
}
}
}
thread_local! {
static FOO: Foo = Foo;
}
let (s, r) = unbounded::<()>();
scope(|scope| {
scope.spawn(|_| {
FOO.with(|_| ());
r.recv().unwrap();
});
scope.spawn(|_| {
thread::sleep(ms(100));
s.send(()).unwrap();
});
})
.unwrap();
}