Threads for Programming Multiprocessor Computers ("multithreading")
The introduction by Intel and AMD of microprocessor chips for PCs (as well as publicity about parallel supercomputers) is drawing attention to the programming concept of multithreading. In a multithreaded program blocks of code called threads run concurrently , thus allowing multiple tasks to be performed at the same time. On a multiprocessor computer each thread can be assigned to a different processor so that the threads truly run simultaneously. But on a single processor computer (e.g., today's PCs) the execution is time sliced so that one thread runs briefly, then the next thread, and so on. This simulates concurrency, but the threads are not really running simultaneously. When 'multicore' PC microprocessors find their way into PCs the threads will actually run concurrently on different processors which will greatly speed program execution.
Object oriented languages like Java and C++ (see previous post) contain definitions of 'classes', each of which is then used to implement multiple objects. Each class defines its own small set of variables and subroutines (these subroutines are termed "methods") which are designed to carry out a set well defined operations. For example, a class might define 52 variables to represent a deck of cards and two subroutines, one subroutine to shuffle the cards and another subroutine to deal the cards. Each time the class is implemented you create a new deck of cards. So for blackjack you could have five decks of cards. A class may be extended by including another class within it. This is how threads are created.
To create a thread in C++ or Java you first define a new class (let's say, the "blinking light class") that includes the predefined THREAD class. Then you could implement five "blinking light objects" from this class. When you ran the program all five lights would blink at the same time because all five threads are executing simultaneously. One common application of threads is in GUI interfaces where a thread is dedicated to watching the graphics input screen. Another application is in simulation programs where multiple calculations are carried out at the same time on separate parts of the thing being simulated.
Multi-tasking PC operating systems use time slicing to run several programs thereby appearing to run the programs simultaneously. A multicore PC chip could actually run different programs on different processors simultaneously. Multithreading brings concurrent operation to a single program. Different threads within the same program run simultaneously.
multithreading some more info

0 Comments:
Post a Comment
<< Home