This is a concept implemented by multitasking operating systems. Every CPU can only execute one task at any given time. To give the user the impression that their computer is running multiple tasks at once, the kernel interrupts a running task after a short, imperceivable delay and switches to another task.
In case of preemptive multitasking, task switches are triggered by a periodic interrupt. The kernel has to make sure the the interrupted task can be restarted later by saving any information needed by the process to continue.
In case of cooperative multitasking, task switches are triggered by the tasks themselves.
Whenever tasks are to be switched, the decision has to be made which task may run next. This is done by the task scheduler, which may choose from a variety of algorithms to optimise latency or performance.