Wednesday, August 6, 2008

Thread - a thread of execution





What are threads?


A thread is a sequence of instructions to be executed within
a program. Normal UNIX processes consist of a single thread
of execution that starts in main(). In other words, each line
of your code is executed in turn, exactly one line at a time.
Before threads, the normal way to achieve multiple
instruction sequences (ie, doing several things at once, in
parallel) was to use the fork() and exec() system calls to
create several processes -- each being a single thread of
execution.

In the UNIX operating system, every process has the following:

1. a virtual address space (ie, stack, data, and code segments)

2. system resources (eg, open files)

3. a thread of execution

These resources are private to each process; for example, processes
cannot peek into one another's address space, open and close
files for one another, etc.



0 comments: