Created
October 15, 2019 15:22
-
-
Save rust-play/55d3844d2c0c5827bd40ec80410d386b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or 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(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