From the course: Threading in C#

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Dead lock

Dead lock

- [Instructor] Locking is deceptively simple. Sometimes we can get into deadlocks while we're doing locks and that's not a good situation to be in. We'll just show a simple deadlock that can occur with simple using two locks. So we'll clear two locks. I'm going to call this thing Cazton Lock. And another lock with my name, Chander. So very simply we can have one thread resolve the reference using system not threading and then inside that we can use the first lock. Again, in order for this to work here you'll have to make it static. Or you can move it inside the method just to make it simple. So once I have Cazton Lock right here I want to make sure I know that we just entered here so I can say console dot write line, Cazton Lock obtained or successful. Once I have this lock that has been obtained what I want to do is have the main thread, now this is a completely different thread, it's not the main thread, what I want to do is have the main thread contend for this particular lock…

Contents