| Index: > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
|
|||||
| First Prev [ 1 2 3 4 ] Next Last |
A common use of threads is having one thread paying attention to the graphical user interface, while others do a long calculation in the background. As a result, the application more readily responds to user's interaction.
An unrelated use of the term thread is for threaded codeFor multi-threaded programming, see Thread (computer science) In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code (at the expense of some speed). It is used in the For, which is a form of code consisting entirely of subroutineIn computer science, a subroutine function procedure or subprogram is a sequence of code which performs a specific task, as part of a larger program, and is grouped as one, or more, statement blocks; such code is sometimes collected into software librarie calls, written without the subroutine call instruction, and processed by an interpreterAn interpreter is a computer program that executes other programs. This is in contrast to a compiler which does not execute its input program (the source code) but translates it into executable machine code (also called object code) which is output to a f or the CPU. Two threaded code languages are ForthForth is a programming language and programming environment. It was initially developed by Chuck Moore at the US National Radio Astronomy Observatory ( NRAO) during the 1960s, formalized as a programming language in 1977, and standardized by ANSI in 1994. and early B programming languageB was the name of a programming language developed at Bell Labs. It is almost extinct, and only remains of historical interest since it represents a transitional phase between BCPL and C. It was mostly the work of Ken Thompson with contributions from Denns.
Threads are distinguished from traditional multi-tasking operating system processes in that processes are typically independent, carry considerable state information , have separate address spaceIn computing, an address space defines a context in which an address makes sense. That is, two addresses may be the same but refer to different things if they belong to different address spaces. Some example address spaces include: Main memory (physical ms, and interact only through system-provided inter-process communicationInter-process communication (IPC) is the exchange of data between one process and another, either within the same computer or over a network. It implies a protocol that guarantees a response to a request. Examples are Unix sockets, RISC OS's messages, Mac mechanisms. Multiple threads, on the other hand, typically share the state information of a single process, share memoryThe terms storage ( U. or memory ( U. refer to the parts of a digital computer that retain physical state ( data) for some interval of time, possibly even after electrical power to the computer is turned off. The anthropomorphic term memory has been used and other resource s directly. Context switching between threads in the same process is typically faster than context switching between processes. Systems like Windows NT and OS/2 are said to have "cheap" threads and "expensive" processes, while in other operating systems there is not so big a difference.
An advantage of a multi-threaded program is that it can operate faster on computer systems that have multiple CPUs, or across a cluster of machines. This is because the threads of the program naturally lend themselves for truly concurrent execution. In such a case, the programmer needs to be careful to avoid race conditions, and other non-intuitive behaviors. In order for data to be correctly manipulated, threads will often need to rendezvous in time in order to process the data in the correct order. Threads may also require atomic operations (often implemented using semaphores) in order to prevent common data from being simultaneously modified, or read while in the process of being modified. Careless use of such primitives can lead to deadlocks.
Use of threads in programming often causes a state inconsistency . A common anti-pattern is to set a global variable, then invoke subprograms that depend on its value. This is known as accumulate and fire.
Operating systems generally implement threads in one of two ways: preemptive multithreading, or cooperative multithreading. Preemptive multithreading is generally considered the superior implementation, as it allows the operating system to determine when a context switch should occur. Cooperative multithreading, on the other hand, relies on the threads themselves to relinquish control once they are at a stopping point. This can create problems if a thread is waiting for a resource to become available. The disadvantage to preemptive multithreading is that the system may make a context switch at an inappropriate time, causing priority inversion or other bad effects which may be avoided by cooperative multithreading.
Traditional mainstream computing hardware did not have much support for multithreading as switching between threads was generally already quicker than full process context switches. Processors in embedded systems, which have higher requirements for real-time behaviors, might support multithreading by decreasing the thread switch time, perhaps by allocating a dedicated register file for each thread instead of saving/restoring a common register file. In the late 1990s, the idea of executing instructions from multiple threads simultaneously has become known as simultaneous multithreading. This feature was introduced in Intel's Pentium 4 processor, with the name Hyper-threading.