Shutdown gracefully in ruby 2.0.0.

Fixes issue #228.

Avoid `ThreadError: can't be called from trap context` on shutdown.

Using mutexes inside traps is deadlockable and prohibited in ruby 2.0.
Instead, do the work in a seperate thread.

See discussion at https://bugs.ruby-lang.org/issues/7917