D
DC
Hi,
I was happy to find the new HashSet<T> class in Framework 3.5, I have
to often used dictionaries with empty values to work with sets.
Recently I ran into a strange performance problem in an application
that adds elements to a HashSet field in many threads. I took far too
long until I isolated that the access to the HashSet, which I forgot
to synchronize, was the reason.
Multiple threads executed HashSet.Add() on a HashSet<int> field and
this did not seem to matter - until some condition (maybe an internal
race) made the CPUs spin up to 100% and never come back. The problem
disappeared when I finally isolated to HashSet.Add() call and first
removed it for testing and then synchronized the HashSet.Add() calls.
While I understand that I made a mistake by not synching the
multithreaded access to a class member, I still think the Frameworks
should have thrown an exception (like it does when one tries to
enumerate and manipulate a collection without syncing). I was not able
to provoke the problem in a test app, though. So my question is: did
someone experience similar problems? Or is this framework behaviour to
be expected?
Regards
DC
I was happy to find the new HashSet<T> class in Framework 3.5, I have
to often used dictionaries with empty values to work with sets.
Recently I ran into a strange performance problem in an application
that adds elements to a HashSet field in many threads. I took far too
long until I isolated that the access to the HashSet, which I forgot
to synchronize, was the reason.
Multiple threads executed HashSet.Add() on a HashSet<int> field and
this did not seem to matter - until some condition (maybe an internal
race) made the CPUs spin up to 100% and never come back. The problem
disappeared when I finally isolated to HashSet.Add() call and first
removed it for testing and then synchronized the HashSet.Add() calls.
While I understand that I made a mistake by not synching the
multithreaded access to a class member, I still think the Frameworks
should have thrown an exception (like it does when one tries to
enumerate and manipulate a collection without syncing). I was not able
to provoke the problem in a test app, though. So my question is: did
someone experience similar problems? Or is this framework behaviour to
be expected?
Regards
DC