Does my Dictionary must use locking mechanism?

Posted by theateist on Stack Overflow See other posts from Stack Overflow or by theateist
Published on 2012-06-17T15:09:57Z Indexed on 2012/06/17 15:16 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

Many threads have access to summary. Each thread will have an unique key for accessing the dictionary;

Dictionary<string, List<Result>> summary;

Do I need locking for following operations?

  1. summary[key] = new List<Result>()
  2. summary[key].Add(new Result());

It seems that I don't need locking because each thread will access dictionary with different key, but won't the (1) be problematic because of adding concurrently new record to dictionary with other treads?

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading