File: basic-sticky.rs

package info (click to toggle)
rust-fragile 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 212 kB
  • sloc: makefile: 24
file content (21 lines) | stat: -rw-r--r-- 589 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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();
}