我是否正确地认为这是正确使用并发字典
private ConcurrentDictionary<int,long> myDic = new ConcurrentDictionary<int,long>();
//Main thread at program startup
for(int i = 0; i < 4; i++)
{
myDic.Add(i, 0);
}
//Seperate threads use this to update a value
myDic[InputID] = newLongValue;
Run Code Online (Sandbox Code Playgroud)
我没有锁等,只是更新字典中的值,即使多个线程可能尝试做同样的事情.