Vous êtes sur la page 1sur 6

Thread (computer science)

From Wikipedia, the free encyclopedia

This article includes a list of references or external links, but its sources remain
unclear because it has insufficient inline citations. Please help to improve this article
by introducing more precise citations where appropriate. (December 2009)

This article is about the concurrency concept. For the form of code consisting entirely of subroutine calls,
see Threaded code. For the collection of posts, see Internet forum#Thread.

A process with two threads of execution.

In computer science, a thread of execution results from a fork of a computer program into two or
more concurrently running tasks. 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.

On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking):


the processor switches between different threads. This context switching generally happens frequently
enough that the user perceives the threads or tasks as running at the same time. On
amultiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each
processor or core running a particular thread or task. Support for threads in programming languages
varies. A number of languages support multiple threads but do not allow them to execute at the same
time. Examples of such languages include Python (at least the C version, also known as CPython, but
not IronPython or Jython), and OCaml, because the parallel support of their runtime environment is based
on a central lock, called the "Global Interpreter Lock" in Python and the "master lock" in Ocaml. Other
languages may be limited because they use threads that are user threads, which are not visible to the
kernel, and thus cannot be scheduled to run concurrently. On the other hand, kernel threads, which are
visible to the kernel, can run concurrently.
Many modern operating systems directly support both time-sliced and multiprocessor threading with a
process scheduler. The kernel of an operating system allows programmers to manipulate threads via
the system call interface. Some implementations are called a kernel thread, whereas a lightweight
process (LWP) is a specific type of kernel thread that shares the same state and information.

What is Process?
A process is a program that is running on your computer. This can be anything from a small
background task, such as a spell-checker or system events handler to a full-blown
application like Internet Explorer or Microsoft Word. All processes are composed of one or
more threads.

Since most operating systems have many background tasks running, your computer is likely
to have many more processes running than actual programs. For example, you may only
have three programs running, but there may be twenty active processes. You can view
active processes in Windows by opening the Task Manager (press Ctrl-Alt-Delete and click
Task Manager). On a Mac, you can see active processes by opening Activity Monitor (in the
Applications->Utilities folder).

The term "process" can also be used as a verb, which means to perform a series of
operations on a set of data. For example, your computer's CPU processes information sent
to it by various programs.
What is the difference between a computer process and thread?
In: Computer Terminology, Computer Programming [Edit categories]

[Improve]
A single process can have multiple threads that share global data and address space with other
threads running in the same process, and therefore can operate on the same data set easily.
Processes do not share address space and a different mechanism must be used if they are to share
data.

If we consider running a word processing program to be a process, then the auto-save and spell check
features that occur in the background are different threads of that process which are all operating on
the same data set (your document).

process

In computing, a process is an instance of a computer program that is being sequentially


executed[1] by a computer system that has the ability to run several computer programs concurrently.

Thread

A single process may contain several executable programs (threads) that work together as a coherent
whole. One thread might, for example, handle error signals, another might send a message about the
error to the user, while a third thread is executing the actual task of the...

Answer
The memory space, where a given application is executed is called - process. A Process is the memory
set aside for an application to be executed in.

Within this process the thing, which is really executed is the thread.

The key difference is that processes are fully isolated from each other; threads share (heap) memory
with other threads running in the same application.

Threads share the address space of the process that created it; processes have their own address.

Threads have direct access to the data segment of its process; processes have their own copy of the
data segment of the parent process.

Threads can directly communicate with other threads of its process; processes must use inter-process
communication to communicate with sibling processes.

Threads have almost no overhead; processes have considerable overhead.

New threads are easily created; new processes require duplication of the parent process.

Threads can exercise considerable control over threads of the same process; processes can only
exercise control over child processes.
Re: Describe the difference between a Thread and a Process?

Re: What is Difference between thread and process?


Answer The major difference between threads and
# 1 processes is
1.Threads share the address space of the
process that
created it; processes have their own address.

2.Threads have direct access to the data


segment of its
process; processes have their own copy of the
data segment
of the parent process.

3.Threads can directly communicate with other


threads of
its process; processes must use interprocess
communication
to communicate with sibling processes.

4.Threads have almost no overhead; processes


have
considerable overhead.

5.New threads are easily created; new


processes require
duplication of the parent process.

6.Threads can exercise considerable control


over threads of
the same process; processes can only exercise
control over
child processes.

7.Changes to the main thread (cancellation,


priority
change, etc.) may affect the behavior of the
other threads
of the process; changes to the parent process
does not
affect child processes.
Re: What is Difference between thread and process?
Answer Process is a program in execution where as
# 2 thread is a
seperate path of execution in a program.

Re: What is Difference between thread and process?


Answer process is a execution of a program and
# 3 program contain set
of instructions but thread is a single
sequence stream
within the process.thread is sometime called
lightweight
process. single thread alows a os to perform
singler task
ata time similarities between process and
threads are:
1)share cpu.
2)sequential execution
3)create child
4)if one thread is blocked then the next will
be start to
run like process.
dissimilarities:
1)threads are not independent like process.
2)all threads can access every address in the
task unlike
process.
3)threads are design to assist onr another and
process
might or not might be assisted on one another.

Re: What is Difference between thread and


process?
Answer Technically, a thread is
# 4 defined as an independent
stream
of instructions that can
be scheduled to run as
such by the
operating system.
So, in summary, in the
UNIX environment a thread:
o Exists within a
process and uses the
process
resources
o Has its own
independent flow of
control as long as
its parent process exists
and the OS supports it
o Duplicates only
the essential resources it
needs to
be independently
schedulable
o May share the
process resources with
other threads
that act equally
independently (and
dependently)
o Dies if the parent
process dies - or
something
similar
o Is "lightweight"
because most of the
overhead has
already been accomplished
through the creation of
its
process.

Whereas in case of
process, every process has
its own
memory management, two
process cannot communicate
without
using IPCS or Sockets,
they do not share
resources and
every process has its own
process ID(pid).

Re: What is Difference between thread and process?


Answer simply say thread is a light weight
# 5 process(flow of
execution throw the process code)....
but process is heavy weight(heavey weight)
process

Vous aimerez peut-être aussi