- in the previous version the IsEmpty could be false, but by time we get
to head.Next.Value we get an exception since Value is now null
- passes existing test cases, although these are not definitive since
they don't show threading issue
- would need to adapt System.Threading.Tasks.ParallelTestHelper to allow
TryPeek() to be called during Enqueue/Dequeue operations to truly
test this change out
}
public bool TryPeek (out T result)
- {
- if (IsEmpty) {
+ {
+ Node first = head.Next;
+
+ if (IsEmpty || first == null) {
result = default (T);
return false;
}
-
- Node first = head.Next;
- result = first.Value;
+
+ result = first.Value;
return true;
}