c# - Concurrent access approach in .NET 3.5 -
this question has answer here:
- return value style question 4 answers
- returning values 2 answers
- .net return value optimization 4 answers
... 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
Post a Comment