1

Edit: For possible duplicated issue, I think the part I haven't solved is that the word managed is still not clear for me whether it would include scheduling, if so, then clearly software threads will not include user threads. But this is strange, since my intuition is that there are only two kinds of threads: either of hardware or of software, and then user threads are belong to neither.

Edit2: The candidate that may solve my question in the possibly duplicated link is this one, which states that it's included, so if this answer with no problem then I accept the closed.


From this answer - software threads vs hardware threads, software threads are threads managed by OS. But I also learn another term called user threads, which are threads that's not kernel threads, i.e. the OS won't know about these threads. So does software threads include user threads?

Kindred
  • 1,229
  • 14
  • 41
  • 1
    Possible duplicate of [Relationship between a kernel and a user thread](https://stackoverflow.com/questions/1178785/relationship-between-a-kernel-and-a-user-thread) – KarelG Dec 06 '18 at 07:37

1 Answers1

3

You are correct, there are hardware threads. Those resemble real physical hardware structures. In other words: hardware threads are implemented by having multiple "copies" of all required "units" within a CPU, allowing the CPU to really, in parallel, execute multiple "threads of execution".

Software threads are "decoupled" of the underlying hardware. They represent a "virtual" resource. The operating system manages these virtual threads, and either uses underlying hardware threads or purely "software only" thread management to execute threads.

Meaning: the OS looks to the underlying CPUs allows and uses the n hardware threads to run m software threads it knows about. Theoretically, when n is 1 (what we had like 20+ years ago), then you don't have any parallelism, but just time slot based scheduling.

The key thing to understand: all the threads the OS manages are "software" threads. As set, consider them a virtual resource. Now: there are simply different types of that resource. Some software threads are reserved for OS kernel usage only. The OS itself uses them, and no user application ever gets to see them. But obviously, applications want "their" own threads, too. Those would be the "user" threads then, as they are created per request in some userspace code.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    As said: CPUs have *units*, such control/arithmetic/floating point/store ... one unit processes one instruction per cycle. Now: if you you want **true** parallel execution of instructions, you need multiple units. In other words: having hardware support for multiple thread means that (parts of) the CPU infrastructure is internally duplicated. It is like a highway: one lane: one stream of cars. 5 lines -> 5 streams of cars, that can flow independently. If you had only one lane you could still "merge" in 5 different lanes, but in the end, they are using the same street. True parallelism --> – GhostCat Dec 06 '18 at 09:43
  • 1
    can only come into existence with multiple lanes. The n==1 ... is like a really old CPU, where there was exactly one lane. Back then, threading was purely "virtual" within the OS, by scheduling all the OS tasks onto that one lane in hardware. @ptr_user7813604 I hope that makes sense and is complete enough now ;-) – GhostCat Dec 06 '18 at 09:45
  • 1
    @ptr_user7813604 Yes, I know, it is a bit fuzzy there. I guess, I rather meant to say: old computers had just "one pipeline" for everything. There was no notion of "hardware threads". In other words: it is more like n == 0 back then. But I thought that would be confusing .. so I turned to n == 1. – GhostCat Dec 06 '18 at 12:15
  • 1
    Just to be clear, a so-called, hardware thread is _not_ a thread in more or less the same way that a parking space is not a car. – Solomon Slow Dec 06 '18 at 16:46
  • 1
    Also, IMO, thinking of a thread as a _resource_ is not helpful. A better way is to think of a thread as an _agent_ that executes your code. – Solomon Slow Dec 06 '18 at 16:51
  • The OS has to manage them. They are resources in the sense of that they come at cost! – GhostCat Dec 06 '18 at 16:56