Message Board


Message Board > Java > A Thread is comparable to a CPU? Wtf?

September 27, 2012, 17:48
Zomg
None
641 posts
"A thread of execution can be thought of as a CPU executing the program" <- I don't understand this quote. How is a Thread comparable with a CPU?
____________
#
May 24, 2013, 21:47
Dennis
どこかにいる
2097 posts

Hmmm isn't this just meant rhetorically speaking?

Like when they say that data bandwidth is comparable with water flowing through a pipe. The wider the pipe the more water can flow.

You shouldn't literally compare a data network with water pipes either..

It's rhetorically speaking.
____________
Kwakkel
#
May 25, 2013, 11:55
Zomg
None
641 posts
Nice question. Did you mean figuratively speaking?

I did some thread programming (and I have a re-exam on it soon. I had 19/20 on the mondeling part) and I know a bit about Threading. I also know that it is bloody annoying to work with! =P

Anyway, a thread could perhaps be seen as a CPU because a Thread has a thing called a 'Thread Local Stack' (You know what a stack is, I guess). A CPU also has a local stack, but it's called the register (which I also assume you know). The CPU stores values in the registers. The operation it does is then Read-Modify-Write. Read from register, modify the value, write back to main memory (RAM). Some info on it: http://en.wikipedia.org/wiki/Processor_register . You can see this behavior in the section 'Critical Sections' of this link: http://tutorials.jenkov.com/ja … l-sections.html , down there where it says A B B B A etc, specifically:

get this.count from memory into register
add value to register
write register to memory

That's what's happening. A thread's local 'register' is the Thread Local Stack. It stores values there. It is like a table with a primary key that no one can touch. A unique table if you will (yes, aren't they all unique? D'oh. =P). A thread has its own stack. However! Concurrency problems can occur. You can read about it in the link. =P

In a nutshell:
A CPU has a place where it stores temporary values. This is called the CPU register. A CPU also executes things. It does the read-modify-write action. A thread has a similar place. This is called the thread local stack. It does the same similar r-m-w action. RAM has something like that too. It's called.. memory address space, but that's as far as the comparison goes for RAM since it doesn't do any writing (I think). A thread's task is to execute something, so yes - it acts as a CPU. A central(ized) processing unit. It is a unit with a unique ID that processes things. It does the same things as the CPU as I just wrote above here. =P

I hope I helped you understand somewhat. If you have any more questions, they are welcome.

Kaaaaaaaaaaaaaaaaaaaaaaaasssssssssssssssssssssss. o/

[Edited on May 25, 2013 by Zomg]
____________
#
May 25, 2013, 11:56
Dennis
どこかにいる
2097 posts

Hmmm, well I'm not really into the low level stuff. :-)
I like to use frameworks, and they are getting quite popular these days!
____________
Kwakkel
#
May 25, 2013, 12:00
Zomg
None
641 posts
Spring! =P Yeah.. I also wrote a library in XML myself. LoL
____________
#

Message Board > Java > A Thread is comparable to a CPU? Wtf?

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!