-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Description
For an application, it's easier and more efficient to use static variables than Arcs. There's no heap allocation, no unnecessary atomic operations, etc.
I guess I could use something utilizing unsafe like this, but I digress.
// One heap allocation:
let flag = Arc::new(AtomicBool::new(false));
signal_hook::flag::register_conditional_shutdown(_, _, Arc::clone(flag))
// Leak it
let flag = unsafe { Arc::into_raw(flag) as &'static AtomicBool };
// Pass to `'static` code without using atomic operationsMaybe it could also support other smart pointers using generics? Like T: Borrow<AtomicBool> + 'static? There's even a blanket impl for &T to &T so my originally proposed use case works.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels