Alpaca Test reports Data Race but don't know why

Mar 31, 2011 at 7:03 AM

Hi!

I wrote some Alpaca Tests and really like the tool and it helped me a lot in finding bad code.
But with the following lines of code I get a Data Race error but don't know why. Can you please be so kind and give me some insights why this is the case?
BTW: I'm using build 61646 from http://ppcp.codeplex.com

using System.Collections.Concurrent;
using System.Threading.Tasks;
using Microsoft.Concurrency.TestTools.UnitTesting;

namespace MOCTestProject
{
public class AlpacaTest
{
[DataRaceTestMethod]
public void AddAndRemove()
{
ConcurrentDictionary<string, MyData> ccd = new ConcurrentDictionary<string, MyData>();

Parallel.Invoke(
() => ccd.TryAdd("k1", new MyData()),

() =>
{
MyData data;
if (ccd.TryRemove("k1", out data))
{
data.Cleanup();
}
}
);
}
}

public class MyData
{
private string data;

public MyData()
{
data = "value";
}

public void Cleanup()
{
data = null;
}
}
}