The following is an example of how deadlock can occur (the original was nuked, possibly due to a somewhat inappropriate title; this is a repost under a different title, which I hope will prove more educational). Think of this as a nontechnical description of deadlock. I do mention computers, but they feature only as part of the deadlock. The deadlocked system is carbon-silicon based, not silicon based.

I managed to become deadlocked with my computer! This occured after I had installed a new version of my printing system (apsfilter) on my home Linux box. The new daemon was set up to detect special file types sent to the printer, and run the appropriate conversions to make it something the printer could understand.. Thus, I can send PostScript to my poor little old HP DeskJet 690C, and apsfilter intercepts it and runs GhostScript to convert it to HP PCLese, before sending it on and causing the printer to spit out pages.

My old apsfilter setup used a temporary file for these conversions, and ran the entire conversion process before starting to print anything. Unknown to me, the new system would spool everything directly on to a pipe: each page hits the printer as soon as it's ready.

I was in a bit of a hurry as I ran "lpr foo.ps" to print out my PostScript file. I hadn't switched the printer on yet. My reasoning was that my time would be better spent doing other things, because meanwhile the spooler was converting the file for me, and nothing would come out if I did switch on the printer. Since I could tell (by the load on my computer suddenly dropping) that the conversion process was done, I could continue doing other stuff until that happened. Except nothing happened. Eventually, I finished everything else I had to do, and the computer still hadn't even started working on the conversion.

After another 5 minutes, I finally got it. Since the new system was spooling on to a pipe, it wouldn't run if the pipe was blocked. Since the printer was off, the pipe was blocked. In other words, the computer was waiting for me to turn the printer ON, before it would start converting. Meanwhile, I was waiting for the computer to finish converting, after which I'd turn the printer ON.

DEADLOCK! Neither of us could progress. Luckily, my advanced deadlock detection algorithms kicked in. Or I would still be sitting there today, blocked doing an infinite amount of nothing.