I have a class:
public class Checker
{
private HashSet<int> _hs = new HashSet<int>();
public bool Check(int a)
{
return Volatile.Read(ref _hs).Contains(a);
}
public void Update(IEnumerable<int> items)
{
Volatile.Write(ref _hs, new HashSet<int>(items));
}
}
Method Check
is called from multiple threads quite often. Method Update
is called from a single thread which monitors some source (database, http service etc.). Is this pattern of Volatile.Read / Volatile.Write
usage correct?