How does task scheduling work?