0

I am confused about the AddOrUpdate method. The document specifically says that the updateValueFactory is not synchronized.

In the MSDN this example was given:

 Parallel.For(0, 10000, i =>
    {
        // Initial call will set cd[1] = 1.   
        // Ensuing calls will set cd[1] = cd[1] + 1
        cd.AddOrUpdate(1, 1, (key, oldValue) => oldValue + 1);
    });

If there are multiple threads trying increment the oldvalue, isn't it possible some of them will be updating a stale value instead?

Thanks.

Koda
  • 1,709
  • 3
  • 14
  • 15
  • 1
    Where do you see that 'updateValueFactory is not synchronized' ? – leppie Dec 04 '12 at 06:16
  • Duplicate of http://stackoverflow.com/questions/10486579/concurrentdictionary-pitfall-are-delegates-factories-from-getoradd-and-addorup - your question is addressed within that thread. – Anthill Dec 04 '12 at 06:23
  • So is the example correct? Or will it not update it properly? – Koda Dec 04 '12 at 06:35
  • Have you read the link I posted? The answer you're looking for is there black on white. – Anthill Dec 04 '12 at 06:38

0 Answers0