Configurable restart threshold

I think these branches may have diverged already, since it's been a while since I did this.  But here's a pull request that you can review and take what you think works.