What is a thread?

In computer programming, a thread is placeholder information associated with a single use of a program that can handle multiple concurrent users.

From the program's point-of-view, a thread is the information needed to serve one individual user or a particular service request.  If multiple users are using the program or concurrent requests from other programs occur, a thread is created and maintained for each of them.  The thread allows a program to know which user is being served as the program alternately gets re-entered on behalf of different users.  (One way thread information is kept by storing it in a special data area and putting the address of that data area in a register.

The operating system always saves the contents of the register when the program is interrupted and restores it when it gives the program control again.)

Multithreading and task are similar and are often confused.

Today's computers can only execute one program instruction at a time, but because they operate so fast, they appear to run many programs and serve many users simultaneously.

The computer operating system (for example, Windows 95) gives each program a "turn" at running, then requires it to wait while another program gets a turn.  Each of these programs is viewed by the operating system as a "task" for which certain resources are identified and kept track of.  The operating system manages each application program in your PC system (spreadsheet, word processor, Web browser) as a separate task and lets you look at and control items on a "task list."  If the program initiates an I/O request, such as reading a file or writing to a printer, it creates a thread so that the program will be reentered at the right place when the I/O operation completes.  Meanwhile, other concurrent uses of the program are maintained on other threads.

Most of today's operating systems provide support for both multitasking and multithreading.  They also allow multithreading within program processes so that the system is saved the overhead of creating a new process for each thread.

The Portable Operating System Interface.4a C specification provides a set of application program interfaces that allow a programmer to include thread support in the program.  Higher-level program development tools and application subsystems and "middleware" also offer thread management facilities.   Object-oriented programming languages also accommodate and encourage multithreading in several ways.

Java supports multithreading by including synchronization modifiers in the language syntax, by providing class developed for multithreading that can be inherited by other classes, and by doing background "garbage collection" (recovering data areas that are no longer being used) for multiple threads.

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.