2

What is the relationship between a CPU thread, an OS thread, and a programming language thread?

I've been wondering what the relationship between a CPU thread, an OS thread, and programming language thread is?

If a processor has n CPU threads (typically equal to the amount of CPU cores), the OS may create m > n threads to be scheduled for execution on the CPU threads (please, correct me if I'm wrong).

How are the programming language threads related to the OS threads? When I create a thread in a programming language, is the language then calling into the OS to create a new thread?

Shuzheng
  • 11,288
  • 20
  • 88
  • 186
  • For the OS thread, from Tanenbaum, Modern Operating Systems: In traditional operating systems, each process has an address space and a single thread of control. In fact, that is almost the definition of a process. Nevertheless, in many situations, it is desirable to have multiple threads of control in the same address space running in quasi-parallel, as though they were (almost) separate processes (except for the shared address space). – Balázs Börcsök May 07 '20 at 19:14
  • I would recommend reading this book as a whole, as this is a deep rabbit hole, and you might want to get know to operating systems abstractions, like address space, processes, scheaduler, multiprogramming, system calls and so on. – Balázs Börcsök May 07 '20 at 19:16
  • Simply speaking, a processor thread is physical processor core, however (https://en.wikipedia.org/wiki/Simultaneous_multithreading) simultaneous multithreading allows the hardware implementation of something like an OS thread. – Balázs Börcsök May 07 '20 at 19:21
  • I am not a Python-guy but I do know, that using C or C++ you can create new processes using system calls (fancy names for functions for the OS specifically) from appropriate libraries, like `fork()` for creating a new process and `pthread_create() ` to create a new thread, in case of POSIX conformant systems. Windows has the equvivalent calls, found in the Win32 API (https://learn.microsoft.com/en-us/windows/win32/api/). You might want to check out this question regarding this https://stackoverflow.com/questions/56810/how-do-i-start-threads-in-plain-c . – Balázs Börcsök May 07 '20 at 19:26

0 Answers0