47 ms·
I added panic("I'm a teapot!"); to the FreeBSD kernel, many many years ago (sys/kern/kern_thread.c). It was for an impossible, cannot-happen scenario. Muc
by darkhelmet 6y ago
I added
panic("I'm a teapot!");
to the FreeBSD kernel, many many years ago (sys/kern/kern_thread.c). It was for an impossible, cannot-happen scenario.
Much to my astonishment/amusement, it did.
- shakna 6y agoHere? [0] I'd be interested in reading the email thread of why it still panic'd, if you have it lying around. [0] https://github.com/freebsd/freebsd/blob/master/sys/kern/kern_thread.c#L630 https://github.com/freebsd/freebsd/blob/master/sys/kern/kern...
- darkhelmet 6y agoThat's the one. In traditional BSD kernels, there is a portable layer and a machine dependent layer. The cpu MD layer for context switching was called cpu_switch(), usually written in assembler. It saved the current state and switched to another. When you regained control of the cpu, you returned from cpu_switch(). There was always somewhere to switch to. When we added multiple threads per process (part of the KSE effort back in the day), a new low level construct was added - cpu_throw(). You switched somewhere else and threw away your context, didn't put the old thread in the run queue, and never returned. We used this for quickly disposing of threads. This was all fine, thread implementations, process/thread schedulers, etc came and went. Somewhere along the way, somebody reused the NetBSD MD/asm layer for one of the powerpc architectures. Of course, NetBSD didn't have cpu_throw(). It was #defined to cpu_switch() because it was close enough and worked. Until somebody tried to use threading on this powerpc architecture. The fake cpu_throw() didn't prevent a return and the system got far enough to reach the upper machine independent layers and hit the panic. This caused some amusement. Particularly as somebody had previously suggested that the panic was unnecessary as it cannot happen but I wanted to keep it anyway.
- lsaferite 6y agoI truly love reading about situations where unreachable code became reachable, much to the astonishment of many. Thanks for that!
- FiatLuxDave 6y agoThis thread reminds me of my experience with the "Call Brian" error code on the 1028 radon monitor: https://news.ycombinator.com/item?id=11397251 https://news.ycombinator.com/item?id=11397251
- mulmen 6y ago> Much to my astonishment/amusement, it did. Surely "just happened" is the default state of all impossible, cannot happen scenarios?
- stingraycharles 6y agoIf that’s the case, you may just have solved the halting problem. :)
- ZephyrBlu 6y ago“Scientists have calculated that the chances of something so patently absurd actually existing are millions to one. But magicians have calculated that million-to-one chances crop up nine times out of ten.” ― Terry Pratchett, Mort
- jayflux 6y agoReminds me of this https://news.ycombinator.com/item?id=23391949 https://news.ycombinator.com/item?id=23391949
- ed25519FUUU 6y ago> I added panic("I'm a teapot!"); to the FreeBSD kernel, many many years ago (sys/kern/kern_thread.c). It was for an impossible, cannot-happen scenario. I know it’s in jest but I absolutely hate to encounter this kind of thing in the wild. It’s a huge anti pattern and tax you put on other people who have to troubleshoot “impossible” scenarios.
- mulmen 6y agoI dunno, seems like a very quackable phrase to me. In fact soon it will probably lead right here!
- markild 6y agoOff topic, but first time I've seen "quackable". Hahaha, I like it! I've tried "duck it" earlier, but it just sounds like I'm stuck with auto correct on.
- wonderlg 6y agoI kind of agree. I remember having to deal with T_PAAMAYIM_NEKUDOTAYIM Sure the solution is still one search away, but…
- gchamonlive 6y agoBut it is one more search away. Computer science has more often than not enough inherent complexity to keep one busy. I don't think we need this extra layer of incidental obscurity.
- msla 6y ago> I know it’s in jest but I absolutely hate to encounter this kind of thing in the wild. It’s a huge anti pattern and tax you put on other people who have to troubleshoot “impossible” scenarios. These days, getting a phrase you can Google effectively is golden. I don't care if I'm pasting "Ream my holes with a bottle brush, Sir Clyde, for I am going to be late for tea!" as long as it gets me the information I need to fix the problem faster. That said, maybe something in Latin would be more couth: https://multicians.org/hodie-natus-est.html https://multicians.org/hodie-natus-est.html > HODIE NATUS EST RADICI FRATER Which means "today unto the Root a brother is born."
- c3534l 6y agoYup. I learned a long time ago that just because its impossible now, doesn't mean there won't be a refactor or something like that and the impossible happens. I still code those checks in precisely because I know they will get thrown.
- tzs 6y agoFor things that cannot happen, I use error code FFF. For what it stands for, that comes from a story told by a friend in college whose best friend had done a summer working at a navy shipyard with several salty old mechanics. Their speech was very liberally sprinkled with the word "fuck". One day, they got an engine in for repair that was in particularly bad shape. After accessing it, one of the mechanics gave his verdict, and at the same time set a new record for the density of "fuck" in their speech. His verdict: "This fucking fucker's fucked".