以下のコードは、クリティカル セクションを形成するために使用されます。
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);
}
}
私の質問は、「obj」の助けを借りて、Monitor.Enter がクリティカル セクションをどのように形成するかです。常にオブジェクトを渡す必要がある場合、フレームワークがオブジェクトを明示的に渡すことができないのはなぜですか。間違いなく、これには何らかの理由があるはずです。誰でも説明できますか?
ありがとう、ヘマント