Information Technology Reference
In-Depth Information
The two types are defined as:
Pre-emptive multitasking . This type of multitasking involves the operating system
controlling how long a process stays on the processor. This allows for smooth multitask-
ing and is used in 32-bit Microsoft Windows programs and the UNIX operating system.
Co-operative multitasking . This type of multitasking relies on a process giving up the
processor. It is used with Windows 3. x programs and suffers from processor hogging,
where a process can stay on a processor and the operating system cannot kick it off.
The logical extension to multitasking programs is to split a program into a number of parts
(threads) and run each of these on the multitasking system (multithreading). A program that
is running more than one thread at a time is known as a multithreaded program. Multi-
threaded programs have many advantages over non-multithreaded programs, including:
They make better use of the processor, where different threads can be run when one or
more threads are waiting for data. For example, a thread could be waiting for keyboard
input, while another thread could be reading data from the disk.
They are easier to test, as each thread can be tested independently of other threads.
They can use standard threads, which are optimised for given hardware.
They also have disadvantages, including:
The program has to be planned properly so that threads know on which other threads
they depend.
A thread may wait indefinitely for another thread which has crashed or terminated.
The main difference between multiple processes and multiple threads is that each process has
independent variables and data, while multiple threads share data from the main program, as
illustrated in Figure H.13.
Process approach
Threads approach
Interlinking
of threads
Process
Process splits
into threads
Independent
threads
Threads
Common sharing
of data between threads
Figure H.13
Process splitting into threads
Search WWH ::




Custom Search