Saturday 2 November 2013

About Multithreading

Before we go into depth about multithreading, you must first know the definition of a thread.


What is a Thread?

In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by an operating system scheduler. The scheduler itself is a light-weight process. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources. In particular, the threads of a process share the latter's instructions (its code) and its context (the values that its variables reference at any given moment).


Multithreading

Multithreading is a technique by which a single set of code can be used by several processors at different stages of execution. Computer central processing units have hardware support to efficiently execute multiple threadsEach user request for a program or system service (and here a user can also be another program) is kept track of as a thread with a separate identity. As programs work on behalf of the initial request for that thread and are interrupted by other requests, the status of work on behalf of that thread is kept track of until the work is completed. The threads do not share the resources of a single core like multiprocessing systems such as multi-core systems. Multithreading aims to increase utilization of a single core by using thread-level as well as instruction-level parallelism.


The key to utilising multithreading support effectively is to think concurrently rather than serially. For example, when you have two subsystems within a program that can execute concurrently, make them individual threads. With the careful use of multithreading, you can create very efficient programs. A word of caution is in order, however: If you create too many threads, you can actually degrade the performance of your program rather than enhance it.

Take note that some overhead is associated with context switching. If you create too many threads, more CPU time will be spent changing contexts than executing your program.


Advantages of Multithreading 

  • If a thread cannot use all the computing resources of the CPU, running another thread can avoid leaving these idle.
  • Improved performance and concurrency
  • If a thread gets a lot of cache misses, the other thread(s) can continue, taking advantage of the unused computing resources, which thus can lead to faster overall execution, as these resources would have been idle if only a single thread was executed.
  • If several threads work on the same set of data, they can actually share their cache, leading to better cache usage or synchronization on its values.

Disadvantages  of Multithreading

  • Multiple threads can interfere with each other when sharing hardware resources such as caches or translation lookaside buffers (TLBs).
  • Execution times of a single thread are not improved but can be degraded, even when only one thread is executing. This is due to slower frequencies and/or additional pipeline stages that are necessary to accommodate thread-switching hardware.
  • Hardware support for multithreading is more visible to software, thus requiring more changes to both application programs and operating systems than multiprocessing.








http://whatis.techtarget.com/http://www.wikipedia.org/http://docs.oracle.com/cd/E13203_01/tuxedo/tux71/html/pgthr5.htm

2 comments:

  1. Emily: "Good job, friends. Now, normally, that is off my free will, I would not have any other comments to make, but since it is part of the assignment, here I go:
    You wrote a "note" that spoke about context-switching and overhead but these terms were not explained previously. Therefore, it is a bit unclear.

    ReplyDelete
  2. Very creative use of graphics however the red is not making the words clear to read and fonts need to be a bit bigger. Continue to keep up the good work

    ReplyDelete