Should i use 2 lock variables or is 1 enough, does it hit performance? What if i would had 3 or 4 Methods that i call from several threads?
public static class Foolocking
{
private static object _syncRoot = new object();
private static List<string> _list1;
private static List<string> _list2;
public Foolocking()
{
_list1 = new List<string>();
_list2 = new List<string>();
}
public void Method1(string s1)
{
lock (_syncRoot)
{
_list1.Add(s1);
}
}
public void Method2(string s2)
{
lock (_syncRoot)
{
_list2.Add(s2);
}
}
}
Reffering to this, would it be correct to lock list1 and list2 itsself?