Overclock.net › Forums › Overclock.net Forum › FAQs › Info: What is a thread?
New Posts  All Forums:Forum Nav:

Info: What is a thread?

post #1 of 5
Thread Starter 
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.
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #2 of 5
Thread Starter 
I hope this will clear up some questions people don't know that they have and add to the discussion in threads about multi-cores/RHT and the like. Let me know what you think
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #3 of 5
Good FAQ. I thought at first it'd be on threads from forums lol
Rep+
post #4 of 5
A thread is something you you make on forums....

-Joking! Nice thread though, +rep ftw
MSI Wind
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Atom 1.6Ghz Intel® 945GSE+ICH7M UMA 1GB DDR2-667 
Hard DriveOptical DriveMonitorCase
80GB N/A 10" 1024x600 MSI Wind 
  hide details  
Reply
MSI Wind
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Atom 1.6Ghz Intel® 945GSE+ICH7M UMA 1GB DDR2-667 
Hard DriveOptical DriveMonitorCase
80GB N/A 10" 1024x600 MSI Wind 
  hide details  
Reply
post #5 of 5
Clear, brief explanation that tells you all you really need to know very simply.
-rep

THAT MEANS MINUS REP, FOOL!
lolz <3
The Beginner
(13 items)
 
  
CPUMotherboardGraphicsRAM
2500+ Barton @ 2310 MHz MSI KT6 Delta Radeon 9800 Pro @ 9800 XT 2x512MB OCZ Platinum @ 210MHz 2-3-2-6 
OSMonitorKeyboardPower
Windows XP Professional Hyundai V560 14.1" CRT Logitech Generic Media Keyboard 300 Watt Sparkle 
CaseMouseMouse Pad
Antec SLK3000B Logitech MX310 Generic 
  hide details  
Reply
The Beginner
(13 items)
 
  
CPUMotherboardGraphicsRAM
2500+ Barton @ 2310 MHz MSI KT6 Delta Radeon 9800 Pro @ 9800 XT 2x512MB OCZ Platinum @ 210MHz 2-3-2-6 
OSMonitorKeyboardPower
Windows XP Professional Hyundai V560 14.1" CRT Logitech Generic Media Keyboard 300 Watt Sparkle 
CaseMouseMouse Pad
Antec SLK3000B Logitech MX310 Generic 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: FAQs
Overclock.net › Forums › Overclock.net Forum › FAQs › Info: What is a thread?