A
akantrowitz
In csharp, what is the correct locking around reading and writing into
a hashtable. Note that the reader is not looping through the keys,
simply reading an item out with a specific key:
If i have the following hashtable h which has multiple readers and 1
writer (on different threads) is this the correct locking below:
[Reader]
lock (h.syncroot)
{
string r = h["Test"];
}
msgbox r;
[Writer]
string w = "Mike";
lock (h.syncroot)
{
h["Test"] = w;
}
a hashtable. Note that the reader is not looping through the keys,
simply reading an item out with a specific key:
If i have the following hashtable h which has multiple readers and 1
writer (on different threads) is this the correct locking below:
[Reader]
lock (h.syncroot)
{
string r = h["Test"];
}
msgbox r;
[Writer]
string w = "Mike";
lock (h.syncroot)
{
h["Test"] = w;
}