Alright, so I decided to jump into this whole “deadlock” thing today. Honestly, I’d heard the term thrown around, but never really got it. So, I figured, what better way to learn than to try and mess things up myself? That’s where these “patch notes 1//22” come in – it’s basically my diary of destruction.

First Steps: Setting the Stage
First things first, I needed some code to play with. I grabbed a simple example online – two threads, each trying to lock two resources (let’s call them Resource A and Resource B) in a different order. It looked something like this:
- Thread 1:
- Lock Resource A
- (Try to) Lock Resource B
- Do some stuff
- Unlock B
- Unlock A
- Thread 2:
- Lock Resource B
- (Try to) Lock Resource A
- Do some stuff
- Unlock A
- Unlock B
Pretty basic, right? I figured this was a recipe for disaster, and I was not wrong.
The Moment of Truth (and Failure)
I ran the code… and waited. And waited. Nothing. The program just hung there, completely frozen. Classic deadlock! Thread 1 had A and was waiting for B, while Thread 2 had B and was waiting for A. They were both stuck, staring at each other like two stubborn goats on a narrow bridge.
I did some changes on my code, and start to run.
Breaking the Deadlock (Kind Of)
Okay, so causing a deadlock was easy. Now, how to get out of it? The most obvious solution, and the one I went with first, was to make sure both threads acquired the resources in the same order. I switched Thread 2 to lock A first, then B. I made Thread go to lock A first, then B.

Ran the code again, and… success! No more hanging. The program actually finished. It felt a bit anticlimactic, to be honest. Like, “Oh, that’s it?”
So basically I changed the lock order, and made a simple implement, and runned. Deadlock solved.
But hey, I learned something! It was a solid start, and I feel like I finally have a basic grip on what deadlocks are and how to avoid them (at least in this super simple scenario). Now, I’m no expert, but if there is something that I learn, I’ll sure be back to my notes, now I fell that I can use this.