main/
main.rs

1#![feature(asm_goto)]
2
3use std::time::Duration;
4
5use static_key::{static_if, static_key};
6
7static_key!(KEY: bool = false);
8
9pub fn test() {
10    loop {
11        while !static_if!(KEY) {}
12        println!("Static key switches to true!");
13        while static_if!(KEY, unlikely) {}
14        println!("Static key switches to false!");
15    }
16}
17
18pub fn update() {
19    loop {
20        std::thread::sleep(Duration::from_secs(1));
21        println!("= true");
22        KEY.set(true);
23        std::thread::sleep(Duration::from_secs(1));
24        println!("= false");
25        KEY.set(false);
26    }
27}
28
29fn main() {
30    std::thread::spawn(|| {
31        test();
32    });
33
34    update();
35}