Fix deadlock at exit (#709)

Some synchronous stop procedures use a GLib's main loop on the main
thread. Therefore, calling it (typically stop()) on the main thread
may causes the dead-lock.

This patch avoids the situation by calling a stop procedure on a
dedicated thread.