Skip to content
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

AlmostOnceCell #133

Closed
tkaitchuck opened this issue Jan 11, 2021 · 4 comments
Closed

AlmostOnceCell #133

tkaitchuck opened this issue Jan 11, 2021 · 4 comments

Comments

@tkaitchuck
Copy link

tkaitchuck commented Jan 11, 2021

As an alternative to #61 or #53
in the case of a no_std environment where lazy initialization is needed, it would be useful to have an implementation which did not block (and hence depend on locking) or spin, but simply re-ran the initialization logic.

So if the initialization has been completed the existing result is used. However if init is attempted from multiple threads concurrently, then it just gets run more than once. For cases where the init is deterministic this provides a clean, zero-dependency, solution.

@matklad
Copy link
Owner

matklad commented Jan 11, 2021

@tkaitchuck
Copy link
Author

😀

@matklad
Copy link
Owner

matklad commented Jan 12, 2021 via email

@tkaitchuck
Copy link
Author

Well it does look inconsistent with the others. I don't know if there is a reason for that.
Unsync has Lazy and OnceCell,
Sync has Lazy and OnceCell,
but Race has OnceBox, OnceNonZeroUsize and OnceBool.

OnceBox appears to be the same as OnceCell in the others but is not named similarly. (It's docs look copied and pasted and make no mention of races).
Lazy is missing. I don't know if there is a reason for that. But if not it is useful and would be good to add.
The other two classes I haven't considered as they don't fit my app's needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants