rust-lang-nursery / lazy-static.rs

A small macro for defining lazy evaluated static variables in Rust.
Apache License 2.0
1.9k stars 108 forks source link

Does lazy_static prevent concurrent read access? #185

Closed vedantroy closed 3 years ago

vedantroy commented 3 years ago

I'm using Sled which supports concurrent method calls for reading/writing. I'm not sure how lazy_static! works (took a read of the source code, couldn't figure it out), but, I'm wondering if lazy_static! will prevent concurrent method calls to the same variable.

From looking through the source, I don't see any Mutex or RwLock so my assumption is yes, but just want to make sure.

Kimundi commented 3 years ago

It has the same semantic as static: You get only &T access to a type T that is also required to implement Sync. So for most types this means you can just concurrently read from them.