ImmutableList() のような不変オブジェクトがある場合。マルチスレッド環境でこのオブジェクトを使用するための推奨される方法は何ですか?
例えば
public class MutableListOfObjects()
{
private volatile ImmutableList objList;
public class MutableListOfObjects()
{
objList = new ImmutableList();
}
void Add(object o)
{
// Adding a new object to a list will create a new list to ensure immutability of lists.
// Is declaring the object as volatile enough or do we want to
// use other threading concepts?
objList = objList.Add(o);
}
// Will objList always use that lest version of the list
bool Exist(object o)
{
return objList.Exist(o);
}
}
目的の動作を実現するには、参照を volatile と宣言するだけで十分ですか? それとも、他のスレッド関数を使用する方が望ましいですか?