N
not_a_commie
Suppose I want to write a synchronized dictionary class with just two
methods:
bool Add(key, value)
bool Remove(key,value)
The Add returns true if the key-value pair already exist or it was
successfully added. It returns false if a key with a different value
was existing. The Remove returns true if the key was nonexistant or
the key-value pair was successfully removed, and it returns false if
the key was existing with a different value.
I can write this fairly trivially by wrapping a dictionary class and
using a lock/monitor mechanism internally in both methods. However,
what I really want is to be able to do the above methods in a
synchronized fashion without using the lock keyword. Is such a thing
possible? Has anyone seen any synchronized dictionaries that don't
lock? i.e., They use the Interlocked class or some other
synchronization mechanism. Every thread in my program hits the above
methods and I don't want to bottleneck there on a lock.
methods:
bool Add(key, value)
bool Remove(key,value)
The Add returns true if the key-value pair already exist or it was
successfully added. It returns false if a key with a different value
was existing. The Remove returns true if the key was nonexistant or
the key-value pair was successfully removed, and it returns false if
the key was existing with a different value.
I can write this fairly trivially by wrapping a dictionary class and
using a lock/monitor mechanism internally in both methods. However,
what I really want is to be able to do the above methods in a
synchronized fashion without using the lock keyword. Is such a thing
possible? Has anyone seen any synchronized dictionaries that don't
lock? i.e., They use the Interlocked class or some other
synchronization mechanism. Every thread in my program hits the above
methods and I don't want to bottleneck there on a lock.