I’ve had my computer completely lock up for a solid minute, and when it unfreezes I ask myself “what did you solve just now that took a whole minute to do?”
antiproton: Think of a computer as a train station. The computer manages the programs (trains) as they move about the station. There are always more trains than there are platforms and tracks, but the computer manages the trains carefully so each train gets time on a platform to do it’s business.
Now imagine one of the trains breaks down for some reason. Every train behind it is forced to stop and wait until the broken down train is fixed before it can move to the platform. If the broken down train is broken down in a way the computer can’t easily fix, it sits there indefinitely.
lcyduh: Applications run on CPU threads. Single-threaded applications load everything on a single thread. You can think of threads as tasks. A single threaded app will do everything on its single thread. In this case, any long running operations will cause the UI to lock up and become unresponsive. This is because the thread is too busy attending to whatever work has been allocated to it in the background – it can’t process UI interaction while this is busy.
This is exactly why multi-threading is preferred for more complex applications. Multi-threaded applications move the background tasks that take a long time onto worker threads that work independently and (mostly) asynchronously from the UI thread. This frees up the UI thread to process user input and report progress of any active tasks that might be running in the background.
Source: I’m a professional software developer.
Howrus: If you send computer into infinite calculations – it’s really don’t matter if he is slow or fast. He will be calculating it forever).
Like: While (TRUE) do I=I+1. It’s freeze because of code bug.
Or let’s say there may be semaphore lock. Process A need resources X and Y to complete his job. He will lock resource X, but Y is already locked for process B, so A will wait until Y is released.
In mean time process B will require resource X to complete his calculations (and he will release resource Y after it). But X is already locked by process A.
So we ended in double lock, that will freeze your system forever. (Or until operation system will interfere and kill both A and B ))) And it’s freeze because of resources allocation.
All this freezes are independent from CPU speed.
KapteeniJ: Your CPU does individual calculations lightning fast, but you gotta consider what it is doing.
First, running the program. CPU starts executing instructions for the program which may take a long time. Say, if you check if a long text file to see if it contains a word, you have to check each word separately. Tell a program to do that, and it will, and won’t be doing anything else until that task is completed.
Worse, CPU may have to wait for hard drive to tell the contents of that file. Hard drive is extremely slow, like, million times slower than RAM. If you happen to end up having to do something, wait for drive, do something, wait for drive, etc, it’s like you switched from gigahertz processor to a kilohertz processor. Instead of billions of operations per second, you do thousands.
To complicate things further, modern OS’s multitask. They give processor to each program for some small time, microseconds maybe, then yank that program out and put a new one in. Again, programs typically reside in RAM, so this switch is very fast, but if you run out of RAM, hard drive is used instead. Suddenly everything gets thousand times slower. OS tries its best to avoid having to place running program to disk, but sometimes things fail.
Sometimes programs also depend on each other so that they wait for each other, which may create unfortunate patterns where programs are given CPU time in unfortunate order and they wait for longer than they should. Like, if program a, b and c need to run so that a runs first, then b, then c, if you have them scheduled to run c, b and then a, you’re again ending up wasting large chunks of time.
All while this goes on, some programs have to be brought to CPU several times every second to check if mouse has moved or if you’ve pressed a key. With modern OS, this requires both OS checking the physical devices and sending flags to appropriate programs, as well as appropriate programs checking these flags