Therad safety
-
Hi buddies, If more than one thread may enter .NET collections (ArrayList, NameObjectCollectionBase, ...) Add() methods should I enclose the code that calls Add() in a lock statement? Also can you tell me a general rule to underestand when I SHOULD call some method only inside a lock statement in a multi-threaded app? Thank you so much, - Mohammad --- "Art happens when you least expect it."
-
Hi buddies, If more than one thread may enter .NET collections (ArrayList, NameObjectCollectionBase, ...) Add() methods should I enclose the code that calls Add() in a lock statement? Also can you tell me a general rule to underestand when I SHOULD call some method only inside a lock statement in a multi-threaded app? Thank you so much, - Mohammad --- "Art happens when you least expect it."
From MSDN documentation on ArrayList: "Public static members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe." As Add() is an instance member, it's not guaranteed to be thread safe, so you should use lock. The documentation should contain thread safety information for all classes. --- b { font-weight: normal; }
-
Hi buddies, If more than one thread may enter .NET collections (ArrayList, NameObjectCollectionBase, ...) Add() methods should I enclose the code that calls Add() in a lock statement? Also can you tell me a general rule to underestand when I SHOULD call some method only inside a lock statement in a multi-threaded app? Thank you so much, - Mohammad --- "Art happens when you least expect it."
Look at
ArrayList.Synchronized
andHashTable.Synchronized
xacc.ide-0.1 released! Download and screenshots -
From MSDN documentation on ArrayList: "Public static members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe." As Add() is an instance member, it's not guaranteed to be thread safe, so you should use lock. The documentation should contain thread safety information for all classes. --- b { font-weight: normal; }
-
Look at
ArrayList.Synchronized
andHashTable.Synchronized
xacc.ide-0.1 released! Download and screenshots -
Look at
ArrayList.Synchronized
andHashTable.Synchronized
xacc.ide-0.1 released! Download and screenshots