#60 Lock-C#

Lock is a thread safe mechanism,where you allow only one thread to access a  block of code(Critical Section) and block other threads,untill the current thread releases the lock(Mutual Exclusion).

lock (object)
 {
 // crtical section
 }

Internally the Lock get’s translated with Monitor.Enter(Object) and Monitor.Exit(object). Lock is a wrapper/high level construct provided by C#.

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