Skip to content

Instantly share code, notes, and snippets.

@Davidtsang
Forked from rust-play/playground.rs
Last active October 15, 2019 15:24
Show Gist options
  • Save Davidtsang/6ec7510e375b08b30e689f5a307f9b09 to your computer and use it in GitHub Desktop.
Save Davidtsang/6ec7510e375b08b30e689f5a307f9b09 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![feature(unwind_attributes)]
use std::os::unix::thread::JoinHandleExt;
use libc::pthread_cancel;
struct DropGuard;
impl Drop for DropGuard {
fn drop(&mut self) {
println!("unwinding foo");
}
}
//----------------
fn foo() {
let _x = DropGuard;
loop {
println!(".");
}
}
fn main() {
let handle = std::thread::spawn(foo);
std::thread::sleep(std::time::Duration::new(0, 10));
unsafe {
pthread_cancel(handle.as_pthread_t());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment