I have question regarding threading in c#.See the code posted below.
public class TestThreading
{
private System.Object lockThis = new System.Object();
public void Function1()
{
lock (lockThis)
{
// Access thread-sensitive resources.
}
}
public void Function2(){
lock (lockThis)
{
// Access thread-sensitive resources.
}
}
}
Now my question is if some thread entered in Function1 (inside lock block) and at the same time another thread enters in Function2 what will happen
- The threads will execute independently.
- The thread which entered in Function 2 Goes to waits until lock is released by Funtion1 thread.
- The thread which entered in Function 2 throws exception.
I am new to c# hence asking simple basic question. Thanks in advance.