Delphi High Performance - Second Edition by Primož Gabrijelčič

Delphi High Performance - Second Edition by Primož Gabrijelčič

Author:Primož Gabrijelčič
Language: eng
Format: epub
Publisher: Packt
Published: 2023-12-15T00:00:00+00:00


Multitasking

In the beginning, operating systems were single-tasking. In other words, only one task (that is, a process) could be executed at a time, and only when it completed the job (when the task terminated) could a new task be scheduled (started).

As soon as the hardware was fast enough, multitasking was invented. Most computers still had only one processor, but through operating system magic, it looked like this processor was executing multiple programs at the same time.

Each program was given a small amount of time to do its job. After that, it was paused and another program took its place. After some indeterminate time (depending on the system load, the number of higher priority tasks, and so on), the program could execute again and the operating system would run it from the position in which it was paused, again only for a small amount of time.

There are two very different approaches to multitasking. In cooperative multitasking, the process itself tells the operating system when it is ready to be paused. This simplifies the operating system but gives a badly written program an opportunity to bring down the whole computer. Remember Windows 3? That was cooperative multitasking at its worst.

A better approach is pre-emptive multitasking, where each process is given its allotted time (typically about a few tens of milliseconds in Windows) and is then pre-empted; that is, the hardware timer fires, takes control from the process, and gives it back to the operating system, which can then schedule the next process.

This approach is used in current Windows, macOS, and all other modern desktop and mobile operating systems. That way, a multitasking system can appear to execute multiple processes at once even if it has only one processor core. Things get even better if there are multiple cores inside the computer, as multiple processes can then really execute at the same time.

The same goes for threads. Single-tasking systems were limited to one thread per process by default. Some multitasking systems were single-threaded (that is, they could only execute one thread per process), but all modern operating systems support multithreading—they can execute multiple threads inside one process. Everything I said about multitasking applies to threads too. Actually, it is the threads that are scheduled, not the processes.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.