Programming

Interview Question : What is Thread?

Quad Core processor and Threads Winged Post

A thread is a single sequential flow of control within a program. the threads of a computer program allows the program to execute sequential actions or many actions at once. Each thread in a program identifies a process that runs when the program asks it to.

The term “Thread” can also be defined as

  1. a smallest unit of processing that can be scheduled by an Operating System.
  2. a portion of code that may be executed independently of the main program.
  3. an ordered sequence of instructions that tells the computer what to do
  4. In online discussion, a thread can refer to a series of related messages.
  5. In e-mail, a thread can refer to a series of replies back and forth pertaining a certain message.

Extended Information:

All programmers are familiar with writing sequential programs. You’ve probably written a program that displays “Hello World!” or sorts a list of names or computes a list of prime numbers. These are sequential programs. That is, each has a beginning, an execution sequence, and an end. At any given time during the runtime of the program, there is a single point of execution.

A thread is similar to the sequential programs described above. A single thread also has a beginning, a sequence, and an end. At any given time during the runtime of the thread, there is a single point of execution. However, a thread itself is not a program; a thread cannot run on its own. Rather, it runs within a program.

Some texts call a thread, a lightweight process. A thread is similar to a real process in that both have a single sequential flow of control. However, a thread is considered lightweight because it runs within the context of a full-blown program and takes advantage of the resources allocated for that program and the program’s environment.

Multiple threads can exists within the same process and share resources such as memory, while different processes do not share these resources.

 

Source / Courtesy : WiseGeek

Previous ArticleNext Article