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: Improve AsyncSubject by using lock-free methods #510

Merged
merged 1 commit into from
May 26, 2018

Conversation

akarnokd
Copy link
Collaborator

This PR changes AsyncSubject to be a lock-free implementation by using atomics.

Since the observable protocol forbids calling the OnXXX methods concurrently, there was no real need for the locked regions and it didn't protect against most races anyway.

Some complication is due to the disposability feature thus that explicit state has to be checked and the relevant exceptions thrown.

The observer management has been also replaced by a straight atomic copy-on-write logic so concurrent subscriptions and subscription-termination races are handled without blocking. Note that the original implementation used ImmutableList.Add which is by itself also copy-on-write thus this change should not worsen the overhead of tracking a lot of observers while the subject is active.

@clairernovotny clairernovotny merged commit f600a69 into dotnet:master May 26, 2018
@akarnokd akarnokd deleted the AsyncSubjectImprovements branch May 30, 2018 13:01
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