Skip to content

Commit

Permalink
TEMPORARY COMMIT: add alloc-tls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlf committed Oct 22, 2017
1 parent 572191b commit 6881ba6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions alloc-tls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ mod tests {
use std::sync::mpsc::{channel, Sender};
use std::cell::UnsafeCell;
use std::thread;
use super::*;

struct Foo(Sender<()>);

Expand All @@ -273,16 +274,18 @@ mod tests {
}

#[test]
fn drop() {
fn lifecycle() {
static mut DROPPED: bool = false;
use super::CallOnDrop;
fn drop() {
unsafe { DROPPED = true }
}
alloc_thread_local!{ static FOO: CallOnDrop = CallOnDrop(drop); }

thread::spawn(|| unsafe { FOO.with(|_| {}).unwrap() })
.join()
thread::spawn(|| unsafe {
assert_eq!((&*FOO.slot.get()).state(), TLSState::Uninitialized);
FOO.with(|_| {}).unwrap();
assert_eq!((&*FOO.slot.get()).state(), TLSState::Initialized);
}).join()
.unwrap();
assert_eq!(unsafe { DROPPED }, true);
}
Expand Down

0 comments on commit 6881ba6

Please sign in to comment.