Fix race condition in scheduler main loop