refactor context switch, and add an empty single thread codepath