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 and a global to store it so we don't have to repeat ourselves.