Wednesday 29 February 2012

Multitasking vs Multithreading:



·        Process is nothing but the program that is executing.
·        Process based multitasking (or) multitasking is the feature that allows the system to run two or more programs concurrently.
·        Example for multitasking: This multitasking enables us to use the java compiler at the same time when we are using text editor.
·        Threads are separate tasks running within a program.
·        In Thread-based multitasking (or) Multithreading, a single program can execute two or more tasks simultaneously.
·        Example for multithreading: a text editor can format the text at the same time that it is printing.
·        In multitasking, a program is the smallest unit of code that can be dispatched by the scheduler.
·        In multithreading, the thread is the smallest unit of code that can be dispatched by the thread scheduler.
·        The processes in multitasking (process-based multitasking), are referred to as heavyweight tasks. Since,
o   Each process requires its own separate address space.
o   Context switching from one process to another is CPU-intensive task needing more time.
o   Inter-process communication between the processes is again expensive (as the communication mechanism has to span separate
·        Multitasking threads cost less in terms of processor overhead (or) simply Multitasking threads requires less overhead than multitasking processes because of the following reasons:
o   Multiple threads in a program share the same address space, and cooperatively share the same heavyweight process.
o   Context switching from one thread to another is less CPU intensive.
o   Inter-thread communication, is less expensive (as threads in the program communicate in the same address space).
·        Multithreading are used to write very efficient programs that make maximum use of CPU, because idle time of the CPU can be kept down to a minimum.
·        This is really important for the interactive and networked internet environments.
Eg:-
    There may be an instruction in a program that is reading a file from a different host on the network. Knowing that reading from a local file system itself is slow compared to the speed of the CPU, reading from a file on a different host on the network is an even slower process. In single threaded environment, the rest of the program waits till the I/O instruction returns. Once the CPU dispatches the I/O instruction it is free. This idle time of the CPU should be put to good use by executing some other part of the system.

No comments:

Post a Comment

IE7 Issues Text Indent

                 Unfortunately IE 7 is still widespread among the users hence while theming we have to give special importance to the grea...