Difference between CPU threads, Kernel threads, OS threads, user threads
Asked Answered
H

1

9

I've been reading a lot about how parallelism is different than concurrency, but I'm having a lot of questions like how can I achieve a parallelism with a programming language like Java?

What I understood so far is with a VM like Java we can only achieve concurrency and parallelism is not in scope of JVM, it's threads mapped to ( I'm confused here ) OS threads or Kernel threads?

To understand the multi-threading one needs to understand how the threads of a VM ( JVM ) or a process are actually mapped down to the CPU hardware. Please help here.

Correct me if I'm wrong, here are few things I think I understand right:

1. CPU threads ( Intel hyper-threading ): Hardware threads provided by adding more registers in CPU having same ALU, so do not actually behave as a dual-CPU ( if 2 threads are there in CPU ) and a "just"-concurrent use of ALU can just mask ( hide by an interleaved MUXing ) a principal inability to deliver indeed a true parallel code-execution.

2. Kernel threads: Started by Kernel and these can be more in number than CPU threads but are a bit expensive to start.

3. OS threads: I don't understand it. I'm guessing this is what you mean when you call native threads and probably same as previous #2 ie Kernel threads.

4. User threads: Just like new Thread() in JVM or .NET. I think they are not recognized as threads by OS so nothing much can be done here from the parallelism perspective.

I need to understand how threads created in #4 are mapped to #1, may be with examples to Windows/Linux/MacOS.

Guys, I understand how wide this question can be but I can live with brief info and link to any detailed documentation. Thanks in advance.

Heyes answered 7/10, 2017 at 10:34 Comment(6)
The java thread is not mapped to cpu thread,but mapped to kernel thread or user thread,it depends the jvm implementation.Different jvm implementation has different thread model,the jvm specification don’t stipulate it.The Oracle jvm hotspot use the 1:1(mapped to kernel) thread model.other jvm has M:1(mapped to user thread),M:N thread model.Renovate
@Renovate can you refer me to any descriptive article that explains how threads in JVM or .NET are executed from CPU's perspective?Heyes
you can see the article threading,and there some other article on the end of it.Renovate
I think you should read the Wikipedia article on threads. Some of the terminology that you have used is rather wrong. (And Intel hyperthreads are NOT threads at all.)Hardworking
I understand how wide this question can be but I can live with brief info and link to any detailed documentation. - For avoid "too broad" you mark your question as off-topic because of "resource request". Actually, as others noted, your question has so many misconceptions, so it is unclear how to ask on it in a brief manner.Kalvin
"Actually, as others noted, your question has so many misconceptions, so it is unclear how to ask on it in a brief manner." - and that is part of why it is Too Broad. Basically, go back and do your research again ... and try to stick to a credible, high quality sources that use proper terminology.Hardworking
S
8

1. Intel Hyperthreading - It is a technology developed by Intel to improve the efficiency of one core because in a lot of its execution time, the CPU waits for retrieving data & code from RAM. The operating system views hyperthreading-cores as two logical processors, each containing separate registers.

2. Kernel Threads - These are managed by the OS-kernel and are scheduled in kernel mode only. They are attached to registers & EIP along with some attributes. These are created and managed by the process by using some "defined" interfaces by the kernel.

3. User Threads - These are created by the userspace process are executed on a kernel thread (because only a kernel one can be scheduled). But multiple user-threads can take turns for executing on a kernel thread, and giving better performance for 'temporary' threads that come & go, due to time saved by not making a system call.

4. OS Threads - OS threads don't have a proper definition to my knowledge. They can be threads used by the OS, or just kernel threads.

There are multiple models by which user-threads execute on kernel-threads - one-to-one, m-to-n & all-to-one, you can google these.

Stepup answered 9/11, 2017 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.