-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Cancelling existing SendRef
#70
Comments
Hmm, something like this would definitely be nice to have, however, I'm not sure if it's really possible with the concurrent ring buffer algorithm. When a Lines 218 to 221 in 0cf1ea2
so the next attempt to push/send a slot will claim the next index. However, the head (readable) index is not advanced until the I think if we wanted to implement a cancellation API like you're describing, we could, but the only way we could do it would be to essentially mark the slot as having been skipped --- sort of like the approach you proposed of sending an empty message, but with the benefit of not waking up the receiver when a slot is skipped. This would still "waste" the slot on this lap (it would be usable again when the ring buffer wraps around), but it would avoid spurious wakeups. There might be a better solution. I'll keep thinking about it. |
Thanks for the prompt reply - yea, it sounds like the only obvious way for this to work would be implementing a way of marking slots as skipped (as if you kept a For the memory usage perspective, as long as you don't abuse the cancellation procedure and it's more of a rare occasion, it should be negligible in most cases. IIUC, it may introduce some extra branching on the tx side (to handle the 'skipped' status), but with mpsc you'd be typically trying to avoid branching and wakeups on the rx side as much as possible. |
Hi! We have a somewhat similar situation where we obtain a We created an |
PR #81 added the capability for senders to skip slots which are still in use by the receiver on the current lap. We could probably implement slot cancelling using similar code. We would need to use an additional bit of state on the slot to mark it as "hey, this slot doesn't actually contain any data, don't try to read from it" from the receiver's perspective, to the |
Wonder if allowing to cancel existing
SendRef
would be possible? E.g. something along the lines ofHere's a particular sample use case:
&[u8]
but have to be combined and processed in a streaming fashion, so each message is aBufRead
reader.SendRef
slot and.read_to_end()
directly into it.SendRef
is dropped, it will be sent away.send_ref.cancel()
which would cancel the reservation and return the slot to the pool - hence this question.Thanks!
The text was updated successfully, but these errors were encountered: