4 ms·
Yes. If I say FOUR is a const Mutex with a 4 in it, whenever I talk about FOUR I get a completely new unlocked Mutex with a 4 in it, unrelated to any other Mute
by tialaramex 4y ago
Yes. If I say FOUR is a const Mutex with a 4 in it, whenever I talk about FOUR I get a completely new unlocked Mutex with a 4 in it, unrelated to any other Mutex regardless of whether it was made the same way.
This might be what you want if you, for some reason, need to make different Mutexes with a 4 in them all the time. But, if you actually meant one Mutex, which intially has a 4 in it, then that's a static variable not a constant.
https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=6639e3f2e7cdc6ae18b47b19ea2ccec2 https://play.rust-lang.org/?version=beta&mode=debug&edition=...
Change FOUR to be static instead of const, and now when we print y each time it's gone up by ten because we're using the same Mutex which is what we presumably intended.
- baby 4y agoWhat's the difference between CONST and STATIC fundamentally?
- notpopcorn 4y agoA const is like a `#define` in C or C++, while a static is a global variable.
- CryZe 4y agoIf those terms mean anything to you: const is an rvalue, static is an lvalue.