Thread of execution
1
This article or section needs references that appear in an accredited publication, like specialized magazines, monographs,
daily press or reliable Internet pages.
You can add them like this or notify the main author of the article [1] in your discussion page by hitting: ~~~~
In operating systems, a thread Execution or subprocess is a feature that allows an application to perform
several tasks at once (concurrently). The different threads of execution share a series of resources such as
such as memory space, open files, authentication situation, etc. This technique allows to simplify the
design of an application that must carry out different functions simultaneously.
A thread is basically a task that can be executed in parallel with another task.
The threads that share the same The same resources, added to these resources, are jointly known
as a process. The fact that the threads of execution of the same process share the resources means that
any of these threads can modify these. When a thread modifies a data in the memory, the other threads
access that modified data immediately.
What is specific to each thread is the program counter, the execution stack and the CPU status ( including the
value of the records.)
The process is still running while at least one of its execution threads is still active. When the process
finishes, all its threads of execution have also ended. Also at the moment when all the threads of
execution are finished, the process no longer exists and all its resources are released.
Some programming languages have design features expressly created to allow the
programmers deal with execution threads (such as Java or Delphi). Others (most) are unaware of the existence of
threads of execution and these must be created through special library calls that depend on the operating system
in which these languages are being used (as in the case of C and C ++).
An example of the use of threads is having a thread attentive to the graphical interface (icons, buttons, windows), while
another thread makes a long operation internally. In this way the program responds more agile to the
interaction with the user. They can also be used by a server application to serve multiple
clients.
Differences between threads and processes
Threads are distinguished from the traditional processes in which processes are -generally- independent, they carry
] fairly state information, and interact only through communication mechanisms given by the system.
On the other hand, many threads generally share other resources directly. In many of the systems
operating that give facilities to the threads, it is faster to change from one thread to another within the same process, which
change from one process to another. This phenomenon is due to the fact that the threads share data and address spaces,
while the processes, being independent, do not. When changing from one process to another the operating system
(through the dispatcher) generates what is known as overhead, which is time wasted by the processor
to perform a context switch (context switch), in this case move from execution status (running) to waiting status
and place the new process in execution. In the threads, as they belong to the same process, to
perform a thread change the lost time is almost negligible.
Operating systems such as Windows NT, OS / 2 and Linux (2.5 or higher) say they have threads " cheap ", and" expensive "processes
while in other systems there is no big difference.
Execution thread
2
Functionality of the threads
Like the processes, the threads they have a state of execution and can synchronize with each other to avoid
resource sharing problems. Generally, each thread has a specific and determined task, such as
how to increase the efficiency of processor usage.
Single thread states
The main thread states are: Execution, Ready, and Locked. It does not make sense to associate states of
suspension of threads since it is a process concept. In any case, if a process is ejected from the main memory
(ram), all its threads must be there since they all share the address space of the process.
Change of states
• Creation: When create a process a thread is created for that process. Then, this thread can create other threads
within the same process, providing an instruction pointer and the arguments of the new thread. The thread
will have its own context and its own column space, and will pass to the end of the ready ones.
• Blocking: When a thread needs to wait for an event, it locks (saving its user records, counter
of program and stack pointers). Now the processor can start executing another thread that is at the end of
Ready while the previous one remains blocked.
• Unlocking: When the event by which the thread was blocked occurs, it passes to the final of the Ready.
• Termination: When a thread ends, both its context and its columns are released ..
Advantages of the threads against processes
Although the threads are generated from the creation of an process, we can say that a process is a thread of
execution, known as Monohilo. But the advantages of threads are given when we speak of Multihilos, which is
when a process has multiple threads of execution which perform different activities, which may or may not be
cooperative with each other. The benefits of threads are derived from the performance implications.
1. It takes much less time to create a new thread in an existing process than to create a process. Some
investigations lead to the result that this is so by a factor of 10.
2. It takes much less time to finish a thread than a process, because when a process is eliminated, the BCP must be deleted
while a thread is removed from its context and stack.
3. It takes much less time to switch between two threads of the same process
4. The threads increase the efficiency of communication between running programs. In most systems
in interprocess communication the kernel must intervene to offer protection of resources and perform
communication itself. In contrast, between threads can communicate with each other without invoking the kernel. Therefore
both, if there is an application that should be implemented as a set of related execution units, it is
more efficient to do so with a collection of threads than with a collection of separate processes.
Thread [19659002] 3
Synchronization of threads
All threads share the same address space and other resources as open files.
Any modification of a resource from one thread affects the environment of the rest of the threads of the
Therefore, it is necessary to synchronize the activity of the different threads so that they do not interfere with each other or corrupt
data structures.
One advantage of multi-threaded programming is that the programs operate with higher speed in systems of
computers with multiple CPUs (multiprocessor systems or through group of machines) since the threads of the
program are lent v erdaderamente for the concurrent execution. In such a case the programmer needs to be careful
to avoid career conditions (problem that happens when different threads or processes alter data
that others are also using), and other non-intuitive behaviors. The threads usually require a meeting
to process the data in the correct order. It is possible that the threads require atomic operations to prevent
that the common data be changed or read while they are being modified, for which usually
they use the semaphores. Neglecting this can generate interlock.
Multithreaded forms
Operating systems generally implement threads in two ways:
• Adherent multithreading: allows the operating system to determine when there should be a change of context. The
disadvantage of this is that the system can make a change of context at an inappropriate time, causing a
phenomenon known as reversal of priorities and other problems.
• Cooperative multithreading: it depends on the same thread to abandon the control when it reaches a stopping point, which
can bring problems when the thread waits for the availability of a resource.
Multi-threaded hardware support has been available for a relatively short time. This
feature was introduced by Intel in the Pentium 4, under the name of HyperThreading.
Most common uses
The most common uses are in SMPP technologies and SMS for telecommunications here there are many processes
running at the same time and all requiring a service.
Interactive and background work
For example, in a spreadsheet program a thread may be viewing the menus and reading the entry of the
user while another thread executes the orders and updates the spreadsheet. This measure usually increases the
speed that is perceived in the application, allowing the program to request the next command before finishing the previous
.
Thread
4
Asynchronous processing
] The asynchronous elements of a program can be implemented as threads. An example is how the softwares of
text processing store temporary files when you are working in that program. A thread is created
whose function is to save a backup while continuing with the write operation by the
user without interfering in it.
Acceleration of execution
Can be executed, for example, a lot while
from Nettech Post http://bit.ly/2s0tthB
No hay comentarios:
Publicar un comentario