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

4.x: Rework & fix SkipUntil with lock-free methods #551

Merged
merged 4 commits into from
Jun 1, 2018

Conversation

akarnokd
Copy link
Collaborator

This PR reimplements the SkipUntil operator to use lock-free methods and also fixes a potential race condition with the original setup when both observables signal OnError concurrently.

{
if (_forward)
_parent.ForwardOnNext(value);
if (Interlocked.CompareExchange(ref _halfSerializer, 1, 0) == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Interlocked.Increment work as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interlocked has to force a new value so it is more expensive in contended cases whereas CAS is generally cheaper, especially on the weaker platforms where increment may be actually implemented as a CAS loop. Here, there is no need to loop.

@danielcweber
Copy link
Collaborator

Merging, I would really like to see that halfserializer-pattern generalized (static methods etc)

@danielcweber danielcweber merged commit c6766f5 into dotnet:master Jun 1, 2018
@akarnokd akarnokd deleted the SkipUntilLockFree branch June 1, 2018 09:09
@akarnokd
Copy link
Collaborator Author

akarnokd commented Jun 1, 2018

I'll post a PR with additional toolsets.

sourceSubscription,
otherSubscription
);
Disposable.TrySetSingle(ref _otherDisposable, parent._other.Subscribe(new OtherObserver(this)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed those before merging, this will for now but it should probably be SetSingle (i.e. throw when already set).

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 this pull request may close these issues.

2 participants