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

Add OnceCell::wait #102

Closed
matklad opened this issue May 13, 2020 · 3 comments · Fixed by #179
Closed

Add OnceCell::wait #102

matklad opened this issue May 13, 2020 · 3 comments · Fixed by #179

Comments

@matklad
Copy link
Owner

matklad commented May 13, 2020

This seems plausible:

impl OnceCell<T> {
  /// Blocks until the cell is populated
  fn wait(&self) -> &T {}
}

The implementaiton should basically stuff the current thread into the waiters list, without attempting to set the value.

@matklad matklad mentioned this issue May 13, 2020
@That3Percent
Copy link

For what it's worth, my opinion is that the addition of this API is a much better idea than making get block and #92 should not be merged.

@matklad
Copy link
Owner Author

matklad commented May 18, 2022

Ironically, I need this now for http://github.com/near/nearcore/ :D

@matklad
Copy link
Owner Author

matklad commented May 18, 2022

Hm, it's interesting that this is slightly not-trivial. Today, when a thread does get_or_try_init and fails (ie, it does not actually initialize the cell), it wakes all other waiters. This makes sense, as every waiter can set the cell.

With wait, we'll get waiters which ideally should not be woken up if we know that the cell is uninint.

matklad added a commit to matklad/nearcore that referenced this issue May 18, 2022
work for near#6826

The ideal fix here would be to go and fix

matklad/once_cell#102

but I am somewhat hesitant to just hack something on top of weak atomics
on the spot :)
matklad added a commit that referenced this issue May 18, 2022
matklad added a commit that referenced this issue May 19, 2022
matklad added a commit that referenced this issue May 19, 2022
matklad added a commit that referenced this issue May 20, 2022
bors bot added a commit that referenced this issue May 20, 2022
177: add OnceCell::wait r=matklad a=matklad

issue: #102

Co-authored-by: Aleksey Kladov <[email protected]>
@bors bors bot closed this as completed in c935154 May 20, 2022
bors bot added a commit that referenced this issue May 23, 2022
179: publish v1.12.0 r=matklad a=matklad

closes #102

Co-authored-by: Aleksey Kladov <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants