Friday, 15 March 2013

Multithreading in C#

  • It is an approach which allows a single program to perform multiple actions simultaneously.  Earlier we had an approach of multitasking where in this case we can execute multiple programs at a given point of time. Operating system is responsible for multitasking where all operating systems are not multitasking Operating system. Windows. MAC, Linux are multitasking Operating systems whereas DOS is a single tasking Operating system. If we want to develop a multithreaded application first the support should be available under the programming language whereas the language will internally take the support of Operating system again. C# language supports multitasking.
  • A thread is a unit of execution which is responsible in executing the program known as main thread. So by default every language is multithreaded.
  • In a single threaded program the execution takes place by performing its actions one by one ie suppose it has started calling a method until and unless that method execution is completed it cannot go to the other methods for execution. So if at all a method is taking more time to execute than the expected until that time all the other methods has to wait.
  • to overcome the problems with single threaded applications, multithreading was designed wherein multithreading we can use a separate thread for calling each method.

  • Multithreading has been designed for maximum utilization of CPU resources. So multithreaded applications execute adopting 2 principals.
  1. Time Sharing: Here Operating system allocates time period for each thread for executing the methods and transfers the control to another thread once the time is elapsed giving equal importance for all the threads to execute.
  2. Maximum utilization of resources: This comes into picture only if the first principal violates ie if a thread could not execute in its given time period for some reason without wasting at that thread Operating system transfers the control to the other threads in execution.

No comments:

Post a Comment