Thread Safe Generic Dictionary Collection
-
Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.
Waleed Eissa Software Developer Sydney
-
Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.
Waleed Eissa Software Developer Sydney
-
Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.
Waleed Eissa Software Developer Sydney
Lock wrapping is required for thread-safety. Without the locking you get dirty reads which can cause a lot of problems in the system. Of course with only add and remove methods I am left wondering how you would use the dictionary.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway -
Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.
Waleed Eissa Software Developer Sydney
If there are lots of concurrent reads and only occasional writes, you could try to use the ReaderWriterLockSlim[^]. If that's still too much locking for your app, you're looking for a lock-free hash table[^]. (according to the presentation, this starts to be faster than locking at >32 processors)
-
Lock wrapping is required for thread-safety. Without the locking you get dirty reads which can cause a lot of problems in the system. Of course with only add and remove methods I am left wondering how you would use the dictionary.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest HemingwayI'm sorry, I don't quite understand your reply. Locking is fine in Add() and Remove() but locking the dictionary every time you try to look up a value is certainly an overkill, this is what I meant when I referred to performance.
Ennis Ray Lynch, Jr. wrote:
Of course with only add and remove methods I am left wondering how you would use the dictionary.
I meant using lock in only Add() and Remove(), I didn't mean a dictionary which only exposes Add() and Remove() :)
Waleed Eissa Software Developer Sydney
-
If there are lots of concurrent reads and only occasional writes, you could try to use the ReaderWriterLockSlim[^]. If that's still too much locking for your app, you're looking for a lock-free hash table[^]. (according to the presentation, this starts to be faster than locking at >32 processors)
This is just what I'm looking for, I think I'm going for the ReaderWriterLockSlim as the dictionary will be used mostly for reading with occasional writes. Thanks a million!
Waleed Eissa Software Developer Sydney
-
Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.
Waleed Eissa Software Developer Sydney