From 512ee60d0ae4a4b74c5a85d2483ee43bb897e7d4 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 18 Oct 2022 19:53:52 +0200 Subject: [PATCH] Added examples folder --- examples/basic-fragile.rs | 18 ++++++++++++++++++ examples/basic-sticky.rs | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/basic-fragile.rs create mode 100644 examples/basic-sticky.rs diff --git a/examples/basic-fragile.rs b/examples/basic-fragile.rs new file mode 100644 index 0000000..54e33fd --- /dev/null +++ b/examples/basic-fragile.rs @@ -0,0 +1,18 @@ +use std::thread; + +use fragile::Fragile; + +fn main() { + // creating and using a fragile object in the same thread works + let val = Fragile::new(true); + println!("debug print in same thread: {:?}", &val); + println!("try_get in same thread: {:?}", val.try_get()); + + // once send to another thread it stops working + thread::spawn(move || { + println!("debug print in other thread: {:?}", &val); + println!("try_get in other thread: {:?}", val.try_get()); + }) + .join() + .unwrap(); +} diff --git a/examples/basic-sticky.rs b/examples/basic-sticky.rs new file mode 100644 index 0000000..e982b1d --- /dev/null +++ b/examples/basic-sticky.rs @@ -0,0 +1,21 @@ +use std::thread; + +use fragile::Sticky; + +fn main() { + fragile::stack_token!(tok); + + // creating and using a fragile object in the same thread works + let val = Sticky::new(true); + println!("debug print in same thread: {:?}", &val); + println!("try_get in same thread: {:?}", val.try_get(tok)); + + // once send to another thread it stops working + thread::spawn(move || { + fragile::stack_token!(tok); + println!("debug print in other thread: {:?}", &val); + println!("try_get in other thread: {:?}", val.try_get(tok)); + }) + .join() + .unwrap(); +}