Stream: general

Topic: lazy_static and spin


RalfJ (Jun 29 2019 at 21:07, on Zulip):

After doing cargo update of a tiny test project, I noticed that lazy_static now depends on spin. Looking at the Cargo.toml, seems that's a non-default feature, but something must be enabling that feature. (I can't find out what though, there are only two reverse dependencies according to cargo tree and neither of them seems to be the one...)
Isn't that a problem? This will mean that when a lazy_static takes a bit to initialize, everyone waiting will wait by spinning instead of properly putting the thread to sleep. Spinlocks make sense when you know exactly that nobody will be in the critical section for too long, but doing this for all lazy_static in the entire program seems a bit too much?

RalfJ (Jun 29 2019 at 21:08, on Zulip):

the reverse tree is:

lazy_static v1.3.0
├── c2-chacha v0.2.2
│   └── rand_chacha v0.2.0
│       └── rand v0.7.0
│           [dev-dependencies]
│           └── cargo-miri-test v0.1.0 (/home/r/src/rust/miri/test-cargo-miri)
└── getrandom v0.1.5
    ├── rand v0.7.0 (*)
    └── rand_core v0.5.0
        ├── rand v0.7.0 (*)
        ├── rand_chacha v0.2.0 (*)
        ├── rand_hc v0.2.0
        │   [dev-dependencies]
        │   └── rand v0.7.0 (*)
        └── rand_pcg v0.2.0
            └── rand v0.7.0 (*)
            [dev-dependencies]
            └── rand v0.7.0 (*)

but the "forwards" tree shows that spin is definitely imported:

lazy_static v1.3.0
└── spin v0.5.0
RalfJ (Jun 29 2019 at 21:13, on Zulip):

there's no way to ask cargo why a feature got enabled, is there? :/

nagisa (Jun 29 2019 at 21:33, on Zulip):

There isn’t, no.

nagisa (Jun 29 2019 at 21:33, on Zulip):

what you want to see is the reverse tree of spin, not lazy_static

RalfJ (Jun 29 2019 at 21:37, on Zulip):

good point

RalfJ (Jun 29 2019 at 21:38, on Zulip):

well, that doesnt bring up anything else though:

spin v0.5.0
└── lazy_static v1.3.0
    ├── c2-chacha v0.2.2
    │   └── rand_chacha v0.2.0
    │       └── rand v0.7.0
    │           [dev-dependencies]
    │           └── cargo-miri-test v0.1.0 (/home/r/src/rust/miri/test-cargo-miri)
    └── getrandom v0.1.5
        ├── rand v0.7.0 (*)
        └── rand_core v0.5.0
            ├── rand v0.7.0 (*)
            ├── rand_chacha v0.2.0 (*)
            ├── rand_hc v0.2.0
            │   [dev-dependencies]
            │   └── rand v0.7.0 (*)
            └── rand_pcg v0.2.0
                └── rand v0.7.0 (*)
                [dev-dependencies]
                └── rand v0.7.0 (*)
simulacrum (Jun 29 2019 at 21:44, on Zulip):

@RalfJ I think getrandom is at fault

simulacrum (Jun 29 2019 at 21:44, on Zulip):

https://github.com/rust-random/getrandom/blob/master/Cargo.toml#L32

simulacrum (Jun 29 2019 at 21:45, on Zulip):

Cargo IIRC doesn't actually respect cfg flags for feature resolution

simulacrum (Jun 29 2019 at 21:45, on Zulip):

but I might be wrong, so take that with a grain of salt

RalfJ (Jun 29 2019 at 21:57, on Zulip):

oh, well that would explain it

RalfJ (Jun 29 2019 at 21:57, on Zulip):

though arguably lazy_static is at fault for letting any crate opt-in to do this, globally.

RalfJ (Jun 29 2019 at 21:57, on Zulip):

or am I unnecessarily worried about spinlocks being used here?

Last update: Nov 21 2019 at 23:35UTC