Context Switching
The CPU can only process one task at a time. But I listen to songs, play games, listen to lectures, and talk to my friends on Discord.
How is this possible?
The reason this is possible is because the computer switches between multiple processes or threads very, very quickly and executes them alternately.
At this time, moving from one task to another is called Context Switching.
Saving and Restoring State
You can save the current state of task A, for example, how far you have calculated it, register values, etc., in the process control block (PCB), and restore the previous state of task B to continue.
Overhead
This switching process is not the CPU actually executing any useful program, but rather the time the operating system uses for internal system management, so if Context Switching becomes too frequent, it can cause the overall performance of the system to deteriorate.