Skip to content
Permalink
Browse files

Add tests for the destructor of `conc::Atomic`.

  • Loading branch information...
ticki committed Jun 10, 2017
1 parent 0b12dde commit 9d42c865f4b5e1c0edb65704041cdbcd4f0bceb0
Showing with 42 additions and 12 deletions.
  1. +42 −12 conc/src/atomic.rs
@@ -312,6 +312,17 @@ mod tests {
use std::sync::atomic::AtomicUsize;
use std::{thread, ptr};

#[derive(Clone)]
struct Dropper {
d: Arc<AtomicUsize>,
}

impl Drop for Dropper {
fn drop(&mut self) {
self.d.fetch_add(1, atomic::Ordering::Relaxed);
}
}

struct Basic;

impl Drop for Basic {
@@ -461,18 +472,7 @@ mod tests {
}

#[test]
fn drop() {
#[derive(Clone)]
struct Dropper {
d: Arc<AtomicUsize>,
}

impl Drop for Dropper {
fn drop(&mut self) {
self.d.fetch_add(1, atomic::Ordering::Relaxed);
}
}

fn drop1() {
let drops = Arc::new(AtomicUsize::default());
let opt = Arc::new(Atomic::new(None));

@@ -504,6 +504,36 @@ mod tests {
assert_eq!(drops.load(atomic::Ordering::Relaxed), 16_000_000 + 16);
}

#[test]
fn drop2() {
let drops = Arc::new(AtomicUsize::default());

let d = Dropper {
d: drops.clone(),
};

let mut j = Vec::new();
for _ in 0..16 {
let d = d.clone();
let opt = opt.clone();

j.push(thread::spawn(move || {
for _ in 0..1_000_000 {
Atomic::new(Some(Box::new(d.clone())));
}
}))
}

for i in j {
i.join().unwrap();
}

::gc();

// The 16 are for the `d` variable in the loop above.
assert_eq!(drops.load(atomic::Ordering::Relaxed), 16_000_000 + 16);
}

#[test]
fn tls() {
thread::spawn(|| BASIC.with(|_| {})).join().unwrap();

0 comments on commit 9d42c86

Please sign in to comment.
You can’t perform that action at this time.