Very much a work in progress!
Of course, right after I started fiddling with this, Dr. Dobbs published a complete solution, wouldn't you just know it?
I've mirrored their code locally: deadlock.zip. The article is in the December 2000 issue, TOC at this DDJ link.
I'd suggest using their code; this is here to remind me to fiddle as I get the time.