With all of the talk about multi-cored cpu's anti-hyperthreading etc and single vs multithreaded applications it is a good thing to know what a thread is.
What is a Thread?
A thread is basically a portion of code that is executed, and ususally repeated. If an application is multi-threaded, the threads are executed in parallel so that multiple things are happening simultaneously in a thread.
What is a Single-Threaded Application?
A single single-threaded application has...one thread. Everything in the program happens sequentially - i.e. the program (say CSS) will check for user input, process, say, a left mouse click, shoot a bullet, check if the bullet hit anything, display the effects. These events will all happen one after the other. These programs are straight forward and easy to program relative to a multi-threaded app. They are more intuitive, the programmer can think, what will happen next? - then make it happen
What is a Multi-Threaded Application
A multi-threaded application is similar to a single threaded one, but things happen simultaneously. In CSS, for example, they could have one thread render everything while one thread monitors user input, while one thread monitors physics, etc. These kinds of programs are very complicated, since not every thread takes the same amount of time to execute once. Also, sometimes two threads will need to use the same data and one may be changing data that the other is trying to change - in the CS:S example, the thread rendering a player needs to know the position of each of the model's parts, while the thread responsible for dealing with user input is trying to make the gun recoil. The position of the arm would be changing at the same time that it is being drawn. This is just one minute example of the bugs that arise in multi-threaded app's.
Can You Make It Simpler Than That?
I'll try. For my computer science class I wrote a Tetris Attack game, which was single threaded. Every part of the code executed sequentially. Without getting into useless details of the program, it had a single thread that repeated until the game exited. First the program checked what stage the game was in. If it was in gameplay stage, it checked user input, moved the cursor/tiles depending on input, checked for matches, scored the game, drew the game to the screen, then repeated. If I were to make the game multi-threaded, I could have had a separate thread continuously check the tiles for matches while the other dealt with everything else. That would have been pretty dumb (it was a simple program), but it can help give you an idea. The reason that multi-threaded app's are hard to write is obvious in this example. What would happen if the game was looking for a match while I was swapping the tile it was checking with another? It would have a wrong idea of the layout of the board and incorrectly calculate matches/my score.
In most of the threads discussing x-threaded app's I wondered if some of the people posting really knew what a thread is. I hope this will clear up some confusion.
What is a Thread?
A thread is basically a portion of code that is executed, and ususally repeated. If an application is multi-threaded, the threads are executed in parallel so that multiple things are happening simultaneously in a thread.
What is a Single-Threaded Application?
A single single-threaded application has...one thread. Everything in the program happens sequentially - i.e. the program (say CSS) will check for user input, process, say, a left mouse click, shoot a bullet, check if the bullet hit anything, display the effects. These events will all happen one after the other. These programs are straight forward and easy to program relative to a multi-threaded app. They are more intuitive, the programmer can think, what will happen next? - then make it happen
What is a Multi-Threaded Application
A multi-threaded application is similar to a single threaded one, but things happen simultaneously. In CSS, for example, they could have one thread render everything while one thread monitors user input, while one thread monitors physics, etc. These kinds of programs are very complicated, since not every thread takes the same amount of time to execute once. Also, sometimes two threads will need to use the same data and one may be changing data that the other is trying to change - in the CS:S example, the thread rendering a player needs to know the position of each of the model's parts, while the thread responsible for dealing with user input is trying to make the gun recoil. The position of the arm would be changing at the same time that it is being drawn. This is just one minute example of the bugs that arise in multi-threaded app's.
Can You Make It Simpler Than That?
I'll try. For my computer science class I wrote a Tetris Attack game, which was single threaded. Every part of the code executed sequentially. Without getting into useless details of the program, it had a single thread that repeated until the game exited. First the program checked what stage the game was in. If it was in gameplay stage, it checked user input, moved the cursor/tiles depending on input, checked for matches, scored the game, drew the game to the screen, then repeated. If I were to make the game multi-threaded, I could have had a separate thread continuously check the tiles for matches while the other dealt with everything else. That would have been pretty dumb (it was a simple program), but it can help give you an idea. The reason that multi-threaded app's are hard to write is obvious in this example. What would happen if the game was looking for a match while I was swapping the tile it was checking with another? It would have a wrong idea of the layout of the board and incorrectly calculate matches/my score.
In most of the threads discussing x-threaded app's I wondered if some of the people posting really knew what a thread is. I hope this will clear up some confusion.






