Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

software threads vs hardware threads

What is the difference between software threads, hardware threads and java threads?

Are software threads, java threads and hardware threads independent or interdependent? I am asking this because, I know Java threads are created inside a process with in jvm (java.exe).

Also is it true that these different process are executed on different hardware threads?

like image 997
Bhadri Avatar asked Apr 08 '11 09:04

Bhadri


People also ask

How are hardware threads different from software threads?

Software threads are threads of execution managed by the operating system. Hardware threads are a feature of some processors that allow better utilisation of the processor under some circumstances. They may be exposed to/by the operating system as appearing to be additional cores ("hyperthreading").

What is the difference between CPU thread and OS thread?

It just means each thread has to wait in line to do a share of its work. Then it gets put on hold while another thread runs some. And so on until it is the first thread's turn again. When software calls for more threads than a CPU has cores, then something has to do the task/thread switching.

Is hyper-threading software or hardware?

Intel® Hyper-Threading Technology is a hardware innovation that allows more than one thread to run on each core.

What is meant by threads in system software?

In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system.


1 Answers

A "hardware thread" is a physical CPU or core. So, a 4 core CPU can genuinely support 4 hardware threads at once - the CPU really is doing 4 things at the same time.

One hardware thread can run many software threads. In modern operating systems, this is often done by time-slicing - each thread gets a few milliseconds to execute before the OS schedules another thread to run on that CPU. Since the OS switches back and forth between the threads quickly, it appears as if one CPU is doing more than one thing at once, but in reality, a core is still running only one hardware thread, which switches between many software threads.

Modern JVMs map java threads directly to the native threads provided by the OS, so there is no inherent overhead introduced by java threads vs native threads. As to hardware threads, the OS tries to map threads to cores, if there are sufficient cores. So, if you have a java program that starts 4 threads, and have 4 or more cores, there's a good chance your 4 threads will run truly in parallel on 4 separate cores, if the cores are idle.

like image 161
mdma Avatar answered Sep 23 '22 15:09

mdma