-
Notifications
You must be signed in to change notification settings - Fork 112
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
Is it possible for loom::sync::Mutex::new
to be const available?
#320
Comments
I don't think that would be possible. Loom primitives must be dropped and recreated between each run. |
They will still get dropped and recreated during each run. What I meant is to change #[derive(Debug, Copy, Clone)]
pub(crate) struct Mutex {
state: OnceCell<object::Ref<State>>,
} |
If its in a global, then you can't recreate it after it is first initialized? |
No it's not global, it's still a local variable, just that it uses That will allow |
If you are ok with bumping msrv to 1.63, adding |
I don't think its necessary for us to do this. Even if we don't use it in globals, making it const will make people think that using it in globals is possible, but it is incorrect and will not work. We can duplicate the |
Yeah I agree that duplicating |
This comes from tokio-rs/tokio#5885 (comment) :
If
loom::sync::Mutex::new
is available inconst
then tokio can remove the boundcfg(not(all(loom, test)))
and make all{Mutex, Notify, ..}::new
available in const without having to define two different versions depending oncfg(not(all(loom, test)))
.From
loom::sync::Mutex
source code:it seems that it's mainly
rt::Mutex
and the MSRV blocking the method from beingconst
.rt::Mutex
relies on globalSTATE
, so the only way to make itconst
is to useOnceCell
to initialize it lazily.The text was updated successfully, but these errors were encountered: