lnobad / lidgren-network-gen3

Automatically exported from code.google.com/p/lidgren-network-gen3
0 stars 0 forks source link

Dictionary<TKey,TValue>.TryGetValue is NOT thread-safe #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I haven't actually run into any issues because of this, but the line 153 of 
NetPeer.cs has a comment that says that Dictionary<TKey,TValue>.TryGetValue is 
thread-safe. It is not, see MSDN:

"A Dictionary<TKey, TValue> can support multiple readers concurrently, as long 
as the collection is not modified."

I haven't actually used the library, but while implementing something similar, 
I looked at its code and stumbled upon that comment. I think this is a bug 
waiting to occur and should be fixed (or the comment removed if there's some 
sort of invisible synchronization going on).

Original issue reported on code.google.com by tristanl...@gmail.com on 7 Nov 2011 at 1:42

GoogleCodeExporter commented 9 years ago
I did some testing and it seems there's no problem as long as adding to the 
dictionary isn't done concurrently. TryGetValue will not throw an exception and 
failing will only yield null which is acceptable in this case.

Original comment by lidg...@gmail.com on 26 May 2012 at 8:53