Open cairijun opened 3 years ago
I feel like the BiLock
's API should take mutable references to self
even if it uses atomic operations internally. It only makes sense for each half to have one exclusive owner.
EDIT: Though that would mess with things given the returned guard is tied to that borrow. So just treat them as mutable even if it isn’t.
Though the documentation says a pair of
BiLock
s can only be used by two "owners", the current API permits aBiLock
object being shared by multiple tasks (Sync + Send
and.lock(&self)
), while the implementation stores only the lastWaker
in.poll_lock
.https://github.com/rust-lang/futures-rs/blob/cc670fdf41703282c1c124fdaa4083637d460096/futures-util/src/lock/bilock.rs#L97-L103
Actual output
Expected behavior
I'm not sure if "a
BiLock
being shared by multiple tasks`" is a legitimate usage, but at least the API doesn't stop people from doing this and the docs doen't seem clear enough about this. I suppose it should at least panic in this scenario.