core: refactor sched_run

`sched_run()` was cluttered, changed changed without refactoring a lot.

Rebased on #1836.
However, "next thread" instead of "new thread" is probably more accurate.