Thursday, October 3, 2013

Threading


Thread :

Thread is the smallest sequence of programmed instructions that can be managed independently  by an operating system scheduler. it comprises of a thread ID, a program counter, a register set and a stack. It shares with other threads belongings to the same process its code section, data section and other operating-system resources, such as open files and signlas.

Benifit of Multithread Programming :


1.  . Responsiveness:  Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user.
2. Resource sharing: By default, threads share the memory and the resources of the process to which they belong. The benefit of code sharing is that it allows an application to have several different threads of activity all within the same address space.
3. Economy: Allocating memory and resources for process creation is costly. Alternatively, because threads share resources of the process to which they belong, it is more economical to create and context switch threads.
4. Utilization of multiprocessor architectures: The benefits of multithreading can be greatly increased in a multiprocessor architecture, where each thread may be running in parallel on a different processor. A single-threaded process can be only run on one CPU, no matter how many are available. Multithreading on a multi-CPU machine increases concurrency.

Disadvantages of a Multithreaded:


1.   Difficulty of writing code
Multithreaded applications are not easy to write. Only experienced programmers should undertake coding for these types of applications.

2.   Difficulty of debugging
It is much harder to replicate an error in a multithreaded application than it is to do so in a single-threaded application. As a result, it is more difficult, in the former case, to identify and verify root causes when errors occur.

Difficulty of managing concurrency
The task of managing concurrency among threads is difficult and has the potential to introduce new problems into an application.

Difficulty of testing
Testing a multithreaded application is more difficult than testing a single-threaded application because defects are often timing-related and more difficult to reproduce.







Difficulty of porting existing code
Existing code often requires significant re-architecting to take advantage of multithreading. Programmers need to:
  • Remove static variables
  • Replace any function calls that are not thread-safe
  • Replace any other code that is not thread-safe
Because the completed port must be tested and re-tested, the work required to port an application is substantial.


No comments:

Post a Comment