We should parody this thread with "What's your OSDev AW HELL NAW! moment?"
That could be the When your OS goes crazy
I had a nice one for that. I started up my brand new task switching, with a lot of new things and two bugs. It looked fine. I suspected it was too slow though, because it took a couple million instructions in Bochs to get to the idle thread, and I had no idea it would do that - a couple thousand was what I expected.
So I turned on tracing and traced *every* instruction. For a few million. And then figured out what happened.
It finishes the boot procedure and enters the task switch logic. It switches to task 1. Task 1 executes, says "hello world" and suspends execution, marking itself as blocked (temp fix). Task switcher finds next task in list and oops - bug 1 - it's uninitialized. So it goes to task X (where X is a random 32-bit number). Luckily it happens to match the range for tasks (which I preallocated to 256MB of address space). No memory mapped there, so it demand-pages in an empty page. That's bug 2 though, it forgets to zero the new page before releasing it. So then it reads another uninitialized block of data for the next task, which is not runnable, and it goes to the next task (uninitialized), to find a not-runnable task demand-paged in, to go to the next ..... and eventually it hit a 0 pointer. Which was the ID of the idle task, so it switches to the idle task and stops.
So two bugs in perfect harmony creating the desired behavior.