Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What's the official explanation for that one? I always seem to forget.

share|improve this question
Can you be a little more specific what on earth you mean by "multitasking illusion"? Just because a processor is single-threaded doesn't mean you can't "multitask" unless you're going to be very academic about the meaning of the word. – Shinrai Apr 11 '11 at 22:47
up vote 4 down vote accepted

Multi-tasking, or multi-threading on a single processor is also called perceived multi-threading. Obviously with one CPU, it is not possible to execute commands simultaneously. Instead we interleave processes, giving the illusion of multi-threading.

As @Journeyman Geek added, this uses preemption. This is where we have some sort of structure (think a queue) where the programs are stored and each process gets so many cycles to execute. Then the currently running program is preempted (or swapped out with another program) and then that program runs. There are many strategies to determining which programs execute when. We could be completely fair (ex: Round Robin) and each program receives a certain time-quantum or we could separate the programs by priority and only execute the lower priority program when there are no more higher-priority programs to execute (ex: Priority Queue).

This is helpful when say you are writing a GUI application and running a long background-task. If this were to be written as a single threaded app, the front-end of the GUI would freeze. However, with two threads, the GUI remains responsive. Even if there is only one CPU, the interleaving of the processes means that the GUI remains responsive while the background-process continues to run and make progress.

share|improve this answer
A GUI could remain responsive because user input generates an interrupt from which the OS could then call a specific handler in the application to perform the GUI work and that handler could return to the background task. Similarly, asynchronous I/O allows (e.g.) disk access without stalling. In addition to timer and I/O interrupts, system calls also provide an opportunity for the OS to perform scheduling. – Paul A. Clayton Feb 23 at 19:19

hyperthreading most likely, with modern systems - in short, part of, but not whole core is duplicated so more threads can be run, per core

share|improve this answer
I'm aware of hyperthreading, that's why I'm asking specifically about single threaded processors, Like a pre-HT Pentium 4, running several applications supposedly at the same time. – overmann Apr 11 '11 at 22:46
oh, you mean pre-emptive or co-operative multitasking? – Journeyman Geek Apr 11 '11 at 22:49
Heh, that's the problem, I don't really know. Maybe those are the terms I'm looking for. Could you explain those in your answer? – overmann Apr 11 '11 at 22:51
chris and john seem to have already. – Journeyman Geek Apr 11 '11 at 22:56

Basically the operating system takes each application (and each thread within each application) in turn and runs it for a few CPU cycles. So if you have 10 applications running, over a 10 second period each will get 1 second's worth of time actually running.

It means that each application runs more slowly than it would if it were the only application running on the computer - but for the vast majority of applications most of their time is spent waiting for user input.

See Wikipedia for more information.

share|improve this answer

I'm not sure what you have in mind, but it brings to mind the user perception that applications are running in parallel. This effect is achieved by interleaving the demands of concurrent processes at such a rate that it looks like every, or at least most, processes are running at the same point in time.

Incidentally, in Unix parlance the focus shifts to the perception that the system appears dedicated to each user's requests. We call this simply "multiuser."

share|improve this answer

Basically when you run many application on a single threaded cpu the operating system switches the cpu between the application.This is done so quickly that an illusion of multitasking is created. So basically what happens is that the cpu gives its cycles to the required application and then moves to another and then back to first application. This all is done by operating system. When the cpu switches to another application which is running concurrently the state of pervious application is saved so that when the cpu comes again to that application it remembers the state of application where it was left.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .