Jump to content

Threaded code

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 203.109.250.97 (talk) at 18:11, 5 April 2002. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In a computer program, a sequence of instructions that execute monoithically is known as a thread. In particular, if an operating system can execute multiple threads using time slicing, then it is possible to write a single program that has multiple threads. For all intents and purposes, these threads operate as if they were independent. An advantage of a multi-threaded program is that it can operate faster on machines that have multiple CPUs, or across a cluster of machines. This is because the threaded nature of the algorithm allow true simultaneous, and independent processing. In such a case, the programmer needs to be careful to avoid deadlock. 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 an atomic operation known as a semaphore in order to prevent data from being simultaneously modified, or read while in the process of being modified.