Creating Multithread Applications

By: Jesse Miller

A program executes as a single, sequential flow of control. A program can also be designed to execute multiple tasks. To execute multiple tasks in your program, you can use threads. Implementation of threads and their life cycle is a good programming technique.

A thread is defined as the execution path of a program. Using a thread, unique flow of a control in a program can be defined. Threads are used to run applications that perform large and complex computations.

A central processing unit performs various complex tasks simultaneously. The processes include tasks such as writing and printing a document, installing software, and displaying the date and time on the status bar. All these processes are handled by separate threads.

A process that is executed using one thread is known as a single-threaded process, where the process is a running instance of a program. A single-threaded application can perform only one task at a time. Programs should wait in a queue until other tasks are completed.

To execute more than one task at a time, you can create multiple threads in a program. A process that creates two or more threads is called a multithread process. Any web browser which supports/connects you to internet is a multithread application.

Within the browser, you can print a page in the background while you scroll the page. Other instance would be watching an animated movie and listening to it. Here two applications are working at the same time they are playing video and audio files. Each thread in a multithread process runs at the same time and maintains a different execution flow. A program uses threads to increase the efficiency of a CPU by preventing wastage of the CPU cycles.

In a single-threaded system, an approach called event loop with polling is used. Polling is the process in which a single event is executed at a time. A single thread runs in an infinite loop till its operation is completed. When the operation is completed, the event loop dispatches control to the appropriate event-handler. No more processing can happen in the system until the event-handler returns. This results in the wastage of the CPU time.

Quick Note: Taking the Nonsense out of looking for the right spyware remover

If you really want to take the work out of looking for that right Spyware Protection from a go to the Internet and get a or a Free
Download, In order to prevent your vital information from being ripped from your computer get your Remover Today.

In a single-threaded application if the thread is suspended from execution because it is waiting for a system resource, the entire program stops executing. This limitation can be overcome by using multithreading, which eliminates the event loop with polling approach.

Software
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Software