what is the difference between multitasking and
multithreading?
Answer Posted / sonika
Multithreading
Up to now, we have talked about multiprogramming as a way to allow multiple programs being resident in main memory and (apparently) running at the same time. Then, multitasking refers to multiple tasks running (apparently) simultaneously by sharing the CPU time. Finally, multiprocessing describes systems having multiple CPUs. So, where does multithreading come in?
Multithreading is an execution model that allows a single process to have multiple code segments (i.e., threads) run concurrently within the “context” of that process. You can think of threads as child processes that share the parent process resources but execute independently. Multiple threads of a single process can share the CPU in a single CPU system or (purely) run in parallel in a multiprocessing system
Why should we need to have multiple threads of execution within a single process context?
Well, consider for instance a GUI application where the user can issue a command that require long time to finish (e.g., a complex mathematical computation). Unless you design this command to be run in a separate execution thread you will not be able to interact with the main application GUI (e.g., to update a progress bar) because it is going to be unresponsive while the calculation is taking place.
Of course, designing multithreaded/concurrent applications requires the programmer to handle situations that simply don’t occur when developing single-threaded, sequential applications. For instance, when two or more threads try to access and modify a shared resource (race conditions), the programmer must be sure this will not leave the system in an inconsistent or deadlock state. Typically, this thread synchronization is solved using OS primitives, such as mutexes and sempaphores.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Is Java a dying language?
Say any two properties in beans?
What is balanced tree in java?
Objects or references which of them gets garbage collected?
What is the difference between size and length in java?
What is object english?
Why are functions called methods in java?
Explain enumeration in java?
Can an integer be a string?
Where is singleton pattern used?
What are the advantages of inner classes?
How can I become a good programmer?
What are the 6 mandatory procedures for iso 9001?
How do I run java on windows?
Why do we override tostring method in java?