Re: hashtable - thread safety clarification

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



James wrote:
I read the following in the help for VS C# Express edition:

"Hashtable is thread safe for use by multiple reader threads and a single writing thread."

if I am using a hashtable just like described above, multiple threads read from in but only one thread changes it, should I still be declaring it as 'volatile'?

The statement you quote only covers the safety of the Hashtable's
internal structure - it does not cover thread safety in general.

Volatile will make changes visible to other threads, but that
may not be sufficient for thread safety in your context.

Using lock on a shared object by all threads is most likely
to be most robust way of making your app thread safe.

Arne


.



Relevant Pages

  • Re: Thread safety and atomic assignment (again)
    ... By making the internal field volatile, you have made your class data- ... Are the following code snippets thread safe and why? ... Atomicity and volatileness are two different issues: ... guarantee both visibility and atomicity; ...
    (comp.lang.java.programmer)
  • Re: Newbie: Calling a function and thread safety
    ... I am saying they are "local" ie within class A's scope - basically member ... > other threads, you have no determinism, and in effect no thread safety. ... thread safe, since ...
    (microsoft.public.vc.mfc)
  • Re: What is "Any instance members are not guaranteed to be thread safe" ?
    ... So there are no thread safety issues there, ... > public class SetCustomers: System.Web.UI.Page ... Any instance members are not guaranteed to be thread safe. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Thread safety of collections
    ... > public static members are thread safe, ... > can a collection be accessed safely via multiple threads ... > calling non static methods if the collection is not ... make sure that there's a volatile write in whatever thread sets up the ...
    (microsoft.public.dotnet.framework)
  • Re: vector or arraylist
    ... Which one is better (for speed and memory) ... Vector is obsolete. ... The example, whilst it applies the same thread safety of Vector, it does not make using the arraylist thread safe. ... It merely means individual method invocations are themselves thread safe, but not the state of the collection during the time between them. ...
    (comp.lang.java.help)