Thread (computing): Difference between revisions

Content deleted Content added
cheap/ expensive. GUI
No edit summary
Line 1:
[[ja:スレッド (コンピュータプログラミング)]] [[pl:Wątek (informatyka)]] [[es:hilo(informática)]] [[de:Thread]]
 
Many [[programming language]]s, [[operating system]]s, and other [[software development environmentsenvironment]]s support what are called "'''threads'''" of [[execution]]. Threads[[Thread]]s are similar to [[computer process|processes]], in that both represent a single [[sequence]] of instructions[[instruction]]s executed in parallel with sequences, either by [[time slicing]] or [[multiprocessing]]. This allows a [[program]] to split itself into two or more simultaneously running tasks[[task]]s.
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]].
The user will see the [[application]] responsive.
 
Threads are distinguished from traditional multi-tasking [[computer process|processes]] in that processes are typically independent, carry considerable [[state information]], and interact only through system-provided [[inter-process communication]] mechanisms. Multiple threads, on the other hand, typically share the state information of a single process, share [[memory ]]and other resources[[resource]]s directly. On [[operating systemssystem]]s that have special facilities for threads, it is typically faster for the system to [[context-switch]] between different threads in the same process than to switch between different processes.
Systems like [[Windows NT]] and [[OS/2]] are said to have "cheap" threads and "expensive" processes, while in systems like [[Linux]] there is not so big a [[difference]].
 
An [[advantage]] of a multi-threaded program is that it can operate faster on machines[[machine]]s that have multiple CPUs[[CPU]]s, or across a [[computer cluster|cluster]] of machines. This is because the threaded nature of the algorithms[[algorithm]]s allow true simultaneous and independent [[processing]]. In such a case, the [[programmer]] needs to be careful to avoid [[race condition]]s, and other non-intuitive behaviors[[behavior]]s. 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_(computer_science)|atomic]] operations (often implemented using [[semaphore (programming)|semaphores]]) in order to prevent data from being simultaneously modified, or read while in the process of being modified. Careless use of such primitives[[primitive]]s can lead to [[deadlock]]s.
 
Use of threads in [[programming]] often causes a [[state inconsistency]]. A common [[anti-pattern]] is to set a [[global variable]], then invoke subprograms[[subprogram]]s that depend on its value. This is known as ''[[accumulate and fire]]''.
 
'''See also:''' [[Thread safety]], [[green threads]]
 
The [[Java programming language]] is an example of a [[computer language]] which supports multi-threaded programs.
 
A relatively new [[concept]] is [[simultaneous multithreading]], that was introduced in [[Intel]]'s [[Pentium 4]] 3.06 GHz processor, with the name of [[Hyper-threading]]
 
----
 
See [[threaded code]] for the [[Forth programming language|Forth]] and early [[B programming language]]s, meaning a form of code consisting entirely of [[subroutine]] calls, written without the subroutine call instruction, and processed by an [[interpreter]] or the CPU.