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
materialize() - add backpressure support #3103
Conversation
private final Subscriber<? super Notification<T>> child; | ||
|
||
// guarded by this | ||
private Notification<T> terminalNotification; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be made volatile and there is no need to synchronize to read its value.
7718dc8
to
cc97739
Compare
Thanks @akarnokd, I've updated with those fixes and rebased. |
A quick question about synchronized blocks vs using volatile variables in general. It would also be possible to atomically change a pair like |
That approach is wasteful. You only need an AtomicInteger and its increment/decrement methods. 0 means not busy, 1+ means busy and 2+ means there is still work to be done. The pair of booleans + synchronized, however, plays into the hands of lock elision and biased locking which affects our benchmarks. If it were up to me, I'd use atomics everywhere so we avoid the chance of unnecessary thread suspension due to a lock not available around 2 bytes. |
Thanks, quite right for that pair of objects, was probably a bad example. So under circumstances where we are getting significant lock elision and biased locking is it also the case that the volatile read and write of |
That is a terminal event that happens once, but when the lock optimizations don't happen, you may get a hefty delay. Paying a few dozen nanoseconds for a single volatile write is way better. |
Makes sense, thanks. |
Thanks! |
materialize() - add backpressure support
As mentioned in #3098 the existing version of
materialize
could deliver one more event than requested being the termination event (completion or error).This PR ensures that a termination event is buffered till requested.