Make sure scheduler thread shuts down cleanly.