Scheduler locking

This branch branches off from the regrettably misspelled optimimize_scheduler branch. Please merge only this one or the other, but not both.
Please use a configuration value to drive the path.