Skip to content

Allow &'static AtomicBool in flag module #180

@axelkar

Description

@axelkar

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 operations

Maybe 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions