Serialize the dispose of Zip(IEnumerable) with MoveNext/Current #1079
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IEnumerator.Dispose
should not be called whileMoveNext
orCurrent
is executing as most implementations don't expect a concurrent dispose call I think.This PR adds a basic trampoline around the calls to
MoveNext
andCurrent
. This allows a mutual exclusion between them and Dispose while also rememberingDispose
should be eventually called:_enumerationInProgress
atomically updates to 1: no concurrent MoveNext is happening and the enumerator can be disposed. IfOnNext
runs at this point_enumerationInProgress
atomically updates to 2 and the method quits without doing anything.OnNext
atomically changes_enumerationInProgress
to 1 and callsMoveNext
. A concurrentDispose
on the operator now updates_enumerationInProgress
to 2 and doesn't dispose the enumerator. WhenMoveNext
finishes, it decrements_enumerationInProgress
and since this is non-zero, it knows to dispose the enumerator and quit without doing any further processing.Fixes #132