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
Write an algorithm for quick sort?
What does microservices mean?
Explain restrictions for using anonymous inner classes?
Explain serialization and deserialization in java?
What is difference between final and finally in java?
Can java list be null?
Can a function return a function?
Does a class inherit the constructors of its superclass in java programming?
Does java have extension methods?
Which is bigger float or double java?
What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?
What is the difference between a break statement and a continue statement?
What is return keyword in java?
How do you define a set in java?
What are different types of constants?