It's all handled by the operating system. The os contains a task scheduler whose job is to give cpu time to the various processes that are running. Here is an article that will interest you.
Ancient Dragon
Achieved Level 70
32,275 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,591
Skill Endorsements: 70