Is it a performace cost to use a nested locks to the same object.
Say we have:
public void AddRange(IEnumeratable<Item> items)
{
lock (_syncObject)
{
foreach (Item item in items)
{
InsertItem(item);
}
}
}
public void InsertItem(Item item)
{
lock (_syncObject)
{
//..
}
}
Is it ok to do so “the performance side”?
Thanks in advance.
Lock has costs, I suggest you to implement your code like this: