How can a single core processor run multiple tasks at once?

suresh November 21, 2011
Pinterest Stumbleupon Whatsapp
Ads by Google

In a computer with single core processor, only one task is said to be running at any point of time.

Now, I have doubts. When I’m hearing music, at the same time I’m converting some video into mobile format and at same time editing my document in my single core Pentium processor. So more than one task is running. But I didn’t feel as if only one task or process was running.

I see that all the three tasks are running without interruption and I even think they run in parallel. If only one task was running at any point and also if CPU switched between various processes or tasks, then when I would hear music without interruption and if CPU switched one task to other, another task would have to wait for its turn and that time the music playback or video conversion may stop, but I didn’t feel that. So help me on this topic. Thanks in advance.

  1. Anonymous
    November 23, 2011 at 3:17 pm

    Single CPU systems use scheduling and can achieve multi-tasking because the time of the processor is time-shared by several processes so allowing each process to advance in parallel. So a process runs for some time and another waiting gets a turn.
    Reassigning a CPU from one task to another one is called a context switch. But Context switching has a cost, a programmer must be aware of down in prtformance.
    In a synergy between hardware and operating system, the CPU is allocated to different processes several times per second and this act is called 'time-slicing' so not to be confused with Multi-threading.'time-slicing' is older technology compared to Multi-threading.

  2. Mike
    November 22, 2011 at 11:10 am

    Multitasking is an operating system feature that allows it to switch between tasks making them seem to run simultaneously.

    Multithreading sort of expands this functionality into a single process allowing multiple threads form the same process to run seemingly simultaneous. 

    Neither function requires an actual multi-core process but they do benefit of it in terms of speed, performance and true simultaneous processing.

    some links which may be worth reading:

    Differences Between Multithreading and Multitasking for Programmers

    Multitasking vs. Multithreading
    Multitasking and Multiprocessing

  3. Jay
    November 22, 2011 at 5:31 am

    it is like illusion, when your eye sees 12 or 25 images in a second, you think you watched a video of one second duration.
    similarly  it switches between the tasks several time in a second, and results in multitasking.

    • James Bruce
      November 24, 2011 at 9:21 am

      That's a terrible analogy, you make it sound like video changes only once every second. 

      • Jay
        November 24, 2011 at 9:38 am

        I tried to use FPS as an example, 12 or 25 frames per second= 1 second long video.
        there is nothing like video changes only once every second!

  4. SenneVL
    November 21, 2011 at 10:18 pm

    Correction 1 Gigaflop =1 000 000 000 flops, not 1 000 000. So you can even multiply my example calculations times 1000!
    200 000 000 calculations whil you psuh a button!
    (sory for the mistake, trying to be as fats as a human, appearantly does not work out ;)

  5. SenneVL
    November 21, 2011 at 9:36 pm

    In fact a single core cpu can only handle 1 task at a time. But every task ( a mouseclick for example) consists of hundreds, thousands or even millions of calculations. That makes it possible to do only part of one such a task and then continue doing a part of another task.
    Because each calculation is so incredibly fast, it just _seems_ like the computer is doing stuff in the same time.
    But hey, you say, my mp3 does not stagger if I type! True, that is in part due to the speed, but also in part due to the fact a computer consists of more then one chip and in between those chips, it is full of caches en queues. The cpu can caculate its part to play the next second of mp3 and hand over the result data to the soundcard which will play the second, leaving the cpu to other tasks.
    So exactly how fast is a modern cpu? That is measured often in flops (Floating Point operations per second) 1 floating point operation is a calculation with  fractures. A modern cpu does about 50 to 70 GigaFlops (50 to 70 million flops) per second!!! that is 50 000 per milisecond. To compare: a average human asked to push a button as fast as he can, has the button down for about 4 milliseconds. So when you push a button, the cpu has time to do ~200 000 calculations at least before you lift your finger. pretty fast!!

  6. Jeff
    November 21, 2011 at 9:12 pm

    Hi Suresh,

    You are able to multitask because modern processors use "multithreading", which allows you to perform concurrent processing, even if only a single core processor. The more cores you have, the better the work load is divided up. Each core can execute only one instruction at a time, however it's so fast it seems as if you are running multiple threads simultaneously. 

    Threads that have messages waiting in the queue, are put into the "active pool" which uses the first in, first out prioritization technique in order to arrange which instruction should be called first. The more processors you have, the more instructions that may be executed in a single instance. 

    You can identify a program that isn't using multiple threads because if it gets into a sophisticated operation, it will not respond to user interaction because it's currently performing another action and simply hasn't process the users action. 

    Does this clear things up?
    - Jeff

    • Hardik Raval
      March 13, 2012 at 7:19 am

      what do you mean by core ?? will you please describe this word.....

      • Jeff Fabish
        March 13, 2012 at 7:27 am

        A core is responsible for executing thread cycles. The more cores you have, the more threads you may run simultaneously. Obviously, the more clock cycles you can execute, the faster your system will perform. 

Ads by Google