Cheap and Secure Web Hosting Provider : See Now

Is it correct to say that CPU's only compute threads?

, , No Comments
Problem Detail: 

New to the world of parallel computation. Would it be correct to say that CPU's are actually thread calculators? My understanding currently: a process is composed of multiple threads and a single core on a cpu is capable of executing instructions from 1 thread at a time, sometimes a bit more when taking into account hyper-threading, but essentially it is computing threads. When the CPU, along with all of its cores, are done calculating all of the threads that belong to a specific process then that process would be considered complete.

So like an analogy would be:

A CPU is like a monkey, with N number of mouths (cores). Each mouth is responsable for eating a long chain of bananas (threads) out of wooden crates (processes). We can increase the rate at which some program is finished/emptied, by hooking up more banana chains from it to an empty and waiting core/mouth. A program is called complete if the wooden crate is emptied of all bananas.

Would this interpretation be correct?

Below is an illustration of my current understanding enter image description here

also what are some of the practical differences (programming-wise) of what I can/cannot do with spawning new processes vs threads. I always see something along the lines of processes have their own memory while threads share it but what do they really mean by that? Like in python, can I just go like from thread_a import var_something?

Asked By : Alan

Answered By : vonbrand

Take a step back. In most operating systems, a process is an entity that owns resources, like memory areas, open files, and such. A thread is an entity that can be scheduled (i.e., get a CPU core assigned, has its own contents of registers and local variables). Several threads can exist within the same process, sharing it's resources.

Switching between threads that share memory means that the table pages and cache entries don't have to be flushed, and that is a major cost in current processors (today to access a word in memory can take the same time than hundreds of instructions!).

Note that some systems (like Linux) have a non-standard view of threads, in that you can create a new thread from an existing one and specify in detail exactly what they are to share.

Is using threads or processes a win? No way to answer in full generality. If different threads of execution don't use the same data, it won't matter much (see above), and it can be advantageous for them not to be able to trample on each other's work. Use processes. If they share data intimately, threads are a better match (and will be more efficient). But then again, having several cores accessing the same data gives rise to cache ping-pong and bad performance. Also, taking such a program and rewrite to run on a distributed system (note that current massive machines are NUMA, essentially separate machines connected by an insanely fast network, but still much slower than direct access to memory) will be much harder.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/53112

3200 people like this

 Download Related Notes/Documents

0 comments:

Post a Comment

Let us know your responses and feedback