What's wrong with this code - #6
After a long hiatus, here's the next entry in my not-really-regular-enough-to-honestly-be-called-periodic-(though-I-try-to-keep-up-a-somewhat-reasonable-schedule-I-don't-seem-to-keep-it-since-I'm-lazy-are-you-still-reading-this)-series about C# code.
Anyway, here's some code that I've seen a fair bit, and written myself:
class Notifier
{
ArrayList items = new ArrayList();
public void Add(object o) {
lock (this) {
items.Add(o);
}
}
}
This code will work fine, but it has a latent issue. What is the issue, and how should it be addressed?