Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread-safety in executor initialization #7362

Closed
younes-io opened this issue Jan 7, 2024 · 0 comments
Closed

Thread-safety in executor initialization #7362

younes-io opened this issue Jan 7, 2024 · 0 comments

Comments

@younes-io
Copy link
Contributor

pub fn current() -> &'static Executor<'static> {

Maybe we could do something like this..

pub fn current() -> &'static Executor<'static> {
    static ONCE: Once = Once::new();
    static mut EXECUTOR: MaybeUninit<Executor> = MaybeUninit::uninit();

    unsafe {
        ONCE.call_once(|| {
            EXECUTOR.as_mut_ptr().write(Executor::new());
        });
        &*EXECUTOR.as_ptr()
    }
}

Since I'm not sure how the executor is used elsewhere in the codebase, I'll let the people familiar with the codebase make sure the implementation is comprehensive..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant