jayferd/workqueue — pull request #1 by ryanaip (2011-11-09 02:55:37+00:00)
Title: Avoid deadlock.

Because you had queue.shift inside of a synchronized block, you could get into a deadlocked position — if you're waiting on an empty queue, no one else can get the lock until something is pushed onto the queue.

Instead of using a synchronized mutex to get elements from the queue, this just pushes nil's onto the queue to signify completion. (Anything other than this will result in some complicated check that the queue isn't empty, then get a lock, then check again, then take an element off the queue requirements.)