-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
const std::lazy::Lazy is a performance footgun when "shared" between threads #82842
Comments
Clippy complains:
There are false positives to these lints (https://rust-lang.github.io/rust-clippy/master/#interior_mutable_const), which is why these aren't deny-by-default and not in |
There is no sharing of anything with a |
That difference wasn't clear to me - thanks for clearing that up. I was somewhat puzzled by it since (as a newbie) it seems
That would help a lot. Although, I can't think of an actual use case for |
I think this is a duplicate of #40543, so closing. I hate how I had opened that issue a while back, and then went ahead with creating a library which now falls victim of it :) |
I have a regex that I only want to initialize once, which is why I wrapped it in a
lazy_static
. However when using the unstablelazy
api (see #74465) instead, sharing it between threads causes the initialization function to run every time.Playground
Note that if
static
is used rather thanconst
, it (correctly) fails to compile as it's notSync
.const SyncLazy
has the same issue, but notstatic SyncLazy
, which is the correct thing to use here.The text was updated successfully, but these errors were encountered: