Skip to content

Conversation

danielcweber
Copy link
Collaborator

No description provided.

{
SpinWait.SpinUntil(timer.IsTimerAssigned);
timer.Stop();
}
Copy link
Contributor

@quinmars quinmars Jun 24, 2018

Choose a reason for hiding this comment

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

As far as I understand it, the original code uses here a try-finally-guard to guarantee that the assignment of _timer happens and it waits in the Tick() method, until the _timer is really set. Is this not needed in the new version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's IMO a poor way of achieving synchronization. We can do better in UserWorkItem. If you have a look at UserWorkItem, the backing field of CancelQueueDisposable is only touched by the Disposable-helper methods. These ensure that, no matter what order the calls occur (assignment/disposal or disposal/assignment), we get the desired result. Disposable does it with Interlocked methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, now I understand. so

Disposable.TryDispose(ref _field);
Disposable.TrySetSingle(ref _field, disposable);

Will dispose disposable, that's very clever.

@danielcweber danielcweber merged commit 014d23a into dotnet:master Jun 26, 2018
@danielcweber danielcweber deleted the SimplifyThreadPoolSchedulerTimedSchedule branch June 26, 2018 11:53
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.

3 participants