#Wait based Synchronization Mechanism-Monitor.

Monitors : Monitor is one of  gated synchronization mechanism which consist of two methods which guarantees thread safe behavior.

1.Monitor.Enter : Threads that enter critical section informs other threads  that it had acquired the resource/CS and no more threads can take ownership on the same and other threads requiring the resource/CS must wait.

2.Monitor.Exit :The thread which had acquired resource/CS  releases the ownership on thread.

In C#,Monitors equivalent code is lock.


lock(object)

{

//CS

}

//It is equivalent to Monitor.Enter and Monitor.Exit.

try

{

Monitor.Enter(object)

{

//CS

}

}

Finally()

{

Monitor.Exit(object)

}

 

 

Capture

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s