Hashtable.Synchronzied()

B

bernardpace

Hi,

Using the following code

Hashtable myData = Hashtable.Synchronized(new Hashtable());

Then I will be having a main thread that will write to this hashtable,
and other n threads that will read and write to this hashtable. In the
n threads, when reading and writing, only one thread will be assigned
specifically on place in the hashtable.

Thread 1 will access only data in myData[1]
Thread 2 will access only data in myData[2]
Thread 3 will access only data in myData[3]
....

Having this scenario, is there need to use the lock(this){...}
mechanism on the Hashtable.


Can someone help me out
Thanks in Advance
 
J

Jon Skeet [C# MVP]

Ron said:
You don't need to use lock(this){...}, you are already synchronizing the
hashtable.

Unless, of course, you want to have a whole sequence of operations
synchronized, rather than just one at a time.
 
B

bernardpace

If there is an other Thread thread0, that will have the right to access
all information in Hashtable, will there be the need to use the lock?

Where should it be used in this thread0 or in the other threads, or in
all?

Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top