Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

CopyOnWriteArrayList is dangerously broken #71

Open
abies opened this issue Feb 26, 2015 · 0 comments
Open

CopyOnWriteArrayList is dangerously broken #71

abies opened this issue Feb 26, 2015 · 0 comments

Comments

@abies
Copy link

abies commented Feb 26, 2015

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant