Fix space leaks of Michael-Scott queue and avoid the impossible #64
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.
This PR fixes the space leak issue of the previous implementation (i.e. issue #63). To properly fix the leaks, it is also necessary to avoid a similar leak through the tail, which could previously also retain a reference to a node containing a value. This also means that the optimization to allow the tail to fall further behind needs more care as multiple push operations could race to update the same fallen behind tail.
One approach taken in this fix is that instead of having
head
andtail
point to a node, they actually point directly to the atomic within a node. This also conveniently avoids the impossible pattern match cases of the previous implementation.Another approach taken in this fix is to make sure that the tail does not fall behind. After a successful update of the tail, the new implementation verifies that the tail is still the tail and, if not, tries to update the tail again. If the tail is allowed to fall behind, then it can cause a leak as then the tail could be left pointing to nodes that have already been removed from the queue.