mono / ngit

Automated jgit port to c#
261 stars 151 forks source link

CopyOnWriteArrayList is dangerously broken #71

Open abies opened 9 years ago

abies commented 9 years ago

I was looking for CopyOnWriteArrayList implementation for C# and have ended up here. Please correct your implementation - it is very dangerous if people try to use it for real things. You CANNOT lock on the object you are going to replace in same method. Create some dedicated lock object and synchronize on that. Otherwise, multiple threads can synchronize on different instances of list, losing some updates.

Additionally IndexOf is broken - you need to put reference to list into local variable at very start and use it, rather than iterating through possibly mutating 'this'. Same for Iterator() - list reference can change between filling both arguments.