resque/resque-scheduler — pull request #303 by csfrancis (2013-12-05 15:07:16+00:00)
Title: Fix unsafe Resque::Scheduler shutdown in Ruby 2.0

This fixes the unsafe shutdown of Resque::Scheduler in Ruby 2.0.

Ruby 2.0 does not allow locks to be used in signal handlers, which is what led to the current workaround of spawning a thread to clean up, then joining on it, which is also not safe.

This solution raises an exception on the thread, which will cause the sleeping thread to unblock and then perform cleanup and exit on the main thread, rather than in the signal handler. This is still not perfectly thread safe for all Rubies (see commit comments), but should be safe for MRI.