Bug 18182

Summary: ConcurrentQueue<T>.TryPeek() is not thread safe
Product: [Mono] Class Libraries Reporter: Craig Minihan <craig>
Component: mscorlibAssignee: Bugzilla <bugzilla>
Severity: normal CC: jeremie.laval, mono-bugs+mono
Priority: ---    
Version: 3.2.x   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description Craig Minihan 2014-03-05 07:11:03 UTC
TryPeek() in ConcurrentQueue looks like this:

public bool TryPeek (out T result)
	if (IsEmpty) {
		result = default (T);
		return false;
	Node first = head.Next;
	result = first.Value;       // *** can exception here ***
	return true;

The problem is that between the IsEmpty test and the assignment "result = first.Value" "head.Next" can become null making first == null and causing an exception when it tries to get the field Value from the null instance.

I will fix and create a pull for this issue.
Comment 1 Craig Minihan 2014-03-05 10:39:36 UTC
Fix submitted in Pull #932
Comment 2 Jérémie Laval 2014-03-17 13:38:40 UTC
Fix merged in master