P
Peter
Hi, I have a Dictionary<key, value> which is accessed by three threads.
One thread puts my value objects in the dictionary (occasionally), and
also updates the contents of existing value objects - by finding the
appropriate object via a key and updating the value (this updating
happens several times a second).
Another thread removes "dead" value objects from the dictionary (very
occasionally)
The third thread needs to loop through all the value objects in the
dictionary performing calculations based on their contents. This thread
needs to run maybe once every 10 seconds, do the calculations, and then
loop/wait again. I am not sure exactly how long these calculations will
take - but it will depend very much on the size of the dictionary
(maybe 1 or 2 seconds).
I foresee a problem with these threads accessing the same dictionary.
Especially the need for the third thread to loop over all the values
while it is possible these values could be being updated, or new values
could be being added or old values deleted.
Do I need to "lock" the entire dictionary while the third thread is
looping over the values? Is there a better way to avoid threading
problems?
Thanks for any comments,
Peter
--
One thread puts my value objects in the dictionary (occasionally), and
also updates the contents of existing value objects - by finding the
appropriate object via a key and updating the value (this updating
happens several times a second).
Another thread removes "dead" value objects from the dictionary (very
occasionally)
The third thread needs to loop through all the value objects in the
dictionary performing calculations based on their contents. This thread
needs to run maybe once every 10 seconds, do the calculations, and then
loop/wait again. I am not sure exactly how long these calculations will
take - but it will depend very much on the size of the dictionary
(maybe 1 or 2 seconds).
I foresee a problem with these threads accessing the same dictionary.
Especially the need for the third thread to loop over all the values
while it is possible these values could be being updated, or new values
could be being added or old values deleted.
Do I need to "lock" the entire dictionary while the third thread is
looping over the values? Is there a better way to avoid threading
problems?
Thanks for any comments,
Peter
--