we all know below code is used to form a critical section.
public class CommonResource
{
public object obj = new object();
public void PopularFunction()
{
lock (obj)
{
///Access variable that we want to protect form being accessed concurrently
///This forms critical section
///My question is what is role'obj' plays in forming critical section.
///How it works behind the scene.
}
///Above code can be written as
Monitor.Enter(obj);
///Access variable that we want to protect form being accessed concurrently
///This forms critical section
///My question is what is role'obj' plays in forming critical section.
///How it works behind the scene.
Monitor.Exit(obj);
}
}
My question is how does Monitor.Enter forms a critical section with the help of 'obj'. If we need to always pass an object why cant framework explicitly pass any object. Definitely there has to be some reason behind this. Can anybody explain?
Thanks, Hemant