G
Guest
I have a question regarding synchronization across multiple threads for a
Hashtable. Currently I have a Threadpool that is creating worker threads
based on requests to read/write to a hashtable. One function of the
Hashtable is to iterate through its keys, which apparently is inherently not
thread-safe. Other functions of the Hashtable include
adding/modifying/deleting.
To solve the synchronization issues I am doing two things:
1. Lock the syncroot of the Hashtable for any "write" operations:
Lock(myHashTable.Syncroot)
{ do some writing/deleting }
2. Wrap the Hashtable in a synchronized Hashtable for any iterations:
Hashtable mySynchedTable = Hashtable.Synchronized(myHashTable);
foreach(key in mySynchedTable)
{ .. do some reading }
My question is: is this enough? Is there anything missing, or should this be
enough to ensure synchronization across multiple threads accessing my
Hashtable.
Thanks!
Hashtable. Currently I have a Threadpool that is creating worker threads
based on requests to read/write to a hashtable. One function of the
Hashtable is to iterate through its keys, which apparently is inherently not
thread-safe. Other functions of the Hashtable include
adding/modifying/deleting.
To solve the synchronization issues I am doing two things:
1. Lock the syncroot of the Hashtable for any "write" operations:
Lock(myHashTable.Syncroot)
{ do some writing/deleting }
2. Wrap the Hashtable in a synchronized Hashtable for any iterations:
Hashtable mySynchedTable = Hashtable.Synchronized(myHashTable);
foreach(key in mySynchedTable)
{ .. do some reading }
My question is: is this enough? Is there anything missing, or should this be
enough to ensure synchronization across multiple threads accessing my
Hashtable.
Thanks!