c# - Concurrent access approach in .NET 3.5 -


this question has answer here:

... private static readonly object syncroot = new object(); private dictionary<int, string> mydict = new dictionary<int, string>();  private dictionary<int, string> mydict {         {         dictionary<int, string> dict = null;         lock (syncroot)         {             dict = mydict;  // <- ??             return dict;         }     }     set     {         lock (syncroot)         {             mydict = value;         }     } } 

....

var test = mydict; foreach(var t in test) {     .... } 

in .net 3.5 project found approach concurrent access object. know if there real benefit assign, in section of mydict property, mydict local dict variable before returning it.

the reason question depends on fact author of code believes assigning object local variable allows concurrent threads reading object release correctly.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -