-1

What is the difference between thread and process? Threads can use multi core and process use multi core too. Threads shares same memory but process cant share. What if we use shared memory for multi-Processing? Are they same or not? When we use multi-threading or multi-processing?

I want to know about what is hyper-threading? How can two process or thread use same core on same time? There is 1 ALU only in 1 core. It can be impossible.

I research process and threads. Inspect process explorer. If Chrome create new tab, there is 1-5 process created from Chrome. Every process have 3-10 thread. I don't know why. There is only 6 tab on chrome but lots of process there are.

If I inspect a process from random tab. Its look like. Chrome Process Threads

12
  • There is 1 ALU only in 1 core. - incorrect. Skylake has 4 integer ALU execution ports per core, for example. See How does a single thread run on multiple cores? (it doesn't, a single core finds instruction-level parallelism.) Commented Sep 19 at 9:12
  • Also maybe related: SMT and Hyperthreading : threads vs process Commented Sep 19 at 9:13
  • 1
    Process can share memory too but this is not done by default. OS resources are done by process and not by threads (so they are shared for all threads and replicated during forking). Processes are significantly more expensive than threads. Scheduling multiple processes can be more expensive than threads because processes generally do not share the same address space (this means TLB misses and cache misses). On some platforms, multiple processes cannot be executed on the same core for security reasons (AFAIK Spectre and Meltdown causes Linux devs to consider x86 CPU SMT as being unsafe). Commented Sep 19 at 10:40
  • 1
    Browsers uses processes because of their isolation (remember that OS resources are per processes). So if one process is corrupted or crashes, it does not impact others. Meanwhile, when a thread crashes, the whole process crashes. The same applies for memory corruption. When processes share memory, the shared memory can be corrupted too (which happen in some rare case on Firefox AFAIK -- IDK for Chrome which AFAIK also use shared memory between processes). Because of their isolation, processes tends to consume more memory (there is no free lunch), and more generally more resources. Commented Sep 19 at 10:43
  • @JérômeRichard I understand Its all about security and reliability. Can you tell me which memory can be shared between two process or thread? RAM/L3/L2/L1 which one can be shared between? Thank you for answers. Commented Sep 19 at 13:20

1 Answer 1

0

What is the difference between thread and process?

In a nutshell, a process is a container for all of the resources that are used by one or more threads. Threads execute a program's code. The process contains all of the virtual memory, open file handles, sockets, windows, and other system resources that are used by those threads.

Every "live" process must have at least one "live" thread. Every thread must belong to exactly one process.


Threads shares same memory but process cant share

Threads that belong to the same process automatically share their entire virtual address space. Processes can share parts of their virtual address space in many operating systems (all of the "big" ones, for sure); but it doesn't happen automatically. The cooperating processes must take specific actions—call specific system calls—to create shared memory regions.


what is hyper-threading?

If you want to understand hyper-threading, then you must first understand what a thread context is. In short, a thread's context is the set of all of the values that must be loaded into a CPU's hardware registers so that the CPU can start executing the instructions on behalf of that thread. You've probably heard of "context switch." That's when the operating system scheduler

  • Interrupts a CPU that was running thread A,
  • Copies the values from the CPU's context registers into the "saved context record" for thread A,
  • Copies values from the saved context of thread B into the CPU's context registers, and finally
  • Returns from the interrupt, allowing the CPU to work on behalf of thread B.

A hyper-threaded CPU has two or more complete sets of context registers. That enables it to switch its attention between the instruction streams of two or more threads without any need for all of that interrupting and copying of register values that the Scheduler has to do.

All by itself, that capability gives us some speedup because, for example, memory reads and writes can take a long time as compared to register-to-register operations. A hyper-threaded CPU that starts a memory fetch for thread A may be able to do some work on behalf of thread B while it awaits the value that thread A wanted to read.


How can two process or thread use same core on same time? There is 1 ALU only in 1 core.

Many high-end processors for server, desktop and even mobile systems have so-called superscalar architecture. A single CPU "core" can have several ALUs, and several each of other so-called "functional units." There are various ways that it can make simultaneous use of those functional units including (if it also is a hyper-threaded processor) simultaneously using different ALUs for different threads.


P.S., I won't pretend to understand the engineering decisions—I am not a computer hardware architect—but, if you're asking why not simply put 2 CPU cores on one chip instead of one core with two sets of registers and two of some functional units? Then it's because somebody who spent a long time studying the problem thought it was the optimum way to get a certain level of overall performance out of a certain size of silicon chip.

3
  • That enables it to switch its attention between the instruction streams of two or more threads - Hyperthreading is fine-grained SMT. Instructions from both threads can be in-flight at once, it's not just switch-on-stall. Hyperthreading looks to the OS like separate CPU cores; an OS with hyperthreading support can detect which pairs of cores are actually siblings sharing the same physical core which is useful only for scheduling decisions. An OS without hyperthreading support would just see all the logical cores and assume they're all separate physical cores. Commented Sep 19 at 19:48
  • realworldtech.com/alpha-ev8-smt is a good description, and see also en.wikipedia.org/wiki/Simultaneous_multithreading. Alpha EV8's SMT is the same as Intel's and AMD's. (Intel hired most of the EV8 team after the project was cancelled just before completion; they went on to work on pentium 4 where the SMT implementation was branded as hyperthreading.) Commented Sep 19 at 19:52
  • Anyway, the key point here is that low-throughput code (like with an instruction latency bottleneck such as sum += arr[i] for floating-point) can usefully share the same physical core, not just code with stalls. With CPU pipelines significantly wider than the typical IPC they achieve on most code, there is room for sharing even though they have to compete for cache, and some out-of-order exec resources (like the reorder buffer) are statically partitioned between logical cores. Commented Sep 19 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.