Last active
August 29, 2015 14:19
-
-
Save alexcrichton/ea7a38d32c4f84ea173d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(scoped)] | |
use std::thread; | |
use std::sync::mpsc::{channel, Sender, Receiver}; | |
fn main() { | |
let (tx1, rx1) = channel(); | |
let (tx2, rx2) = channel(); | |
let _b1 = Bomb1(tx1, rx2); | |
let b = Box::new(4); | |
foo(tx2, rx1, &b); | |
} | |
fn foo(done: Sender<()>, start: Receiver<()>, val: &i32) { | |
let _t = thread::scoped(move || { | |
drop(start.recv()); | |
println!("value at {:p} = {}", val, val); | |
drop(done.send(())); | |
}); | |
let _b2 = Bomb2; | |
} | |
struct Bomb1(Sender<()>, Receiver<()>); | |
impl Drop for Bomb1 { | |
fn drop(&mut self) { | |
println!("letting the child go"); | |
drop(self.0.send(())); | |
drop(self.1.recv()); | |
println!("returning from main thread"); | |
} | |
} | |
struct Bomb2; | |
impl Drop for Bomb2 { | |
fn drop(&mut self) { | |
panic!("panicking on main thread"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment