PC Review


Reply
Thread Tools Rate Thread

Re: Hashtable thread safety?

 
 
Ralf Stanke
Guest
Posts: n/a
 
      4th Sep 2005
try this ...

Hashtable ht = Hashtable.Synchronized( new Hashtable() );
Regards,
Ralf

Ralf Stanke
[VENTUZ] The future of presentations
www.ventuz.com

"Aaron Pfeifer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> It doesn't seem completely clear to me which operations I can perform
> while continuing to be thread-safe on a Hashtable. Consider this
> scenario:
>
> Hashtable 'table' contains the following:
> table[1] = 1
> table[2] = 2
> table[...] = ...
> table[Int32.MaxValue] = Int32.MaxValue
>
> The following threads are now running against that same table
>
> Thread 1:
> for( int i = -1; i > Int32.MinValue; i-- )
> {
> table.Add( i, i );
> }
>
> Thread 2:
> for( int i = 1; i < Int32.MaxValue; i++ )
> {
> table.Remove( i );
> }
>
> Thread 3:
> while( true )
> {
> IList list = new ArrayList( table.Keys );
> foreach( int number in list )
> {
> Console.WriteLine( number );
> }
> }
>
>
> Obviously this is unusual, but it's something like what I actually have,
> and I want to know whether or not this is thread-safe or if I need to
> provide some synchronization. Thanks!
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread safety help on Hashtable mattd0878-usenet@yahoo.com Microsoft C# .NET 6 5th Mar 2009 02:38 AM
Hashtable thread safety / documentation =?Utf-8?B?QWRyaWFuIEg=?= Microsoft C# .NET 3 16th Jul 2007 09:35 AM
Re: Hashtable thread safety? 0to60 Microsoft Dot NET Framework 0 20th Sep 2005 06:58 PM
Re: Hashtable thread safety? S. Senthil Kumar Microsoft Dot NET Framework 0 4th Sep 2005 02:45 PM
thread safety of hashtable Keith Langer Microsoft Dot NET 5 26th Dec 2003 09:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.