1

At the moment, I am dealing with operating systems concepts. However, I have a problem understanding the difference between "kernel thread" and "user thread".

So I surfed the internet and saw this post: https://stackoverflow.com/a/15984127/5005715

Unfortunately, I do not understand what's the difference between "green threads" and "user threads". For me it is basically the same.

Am I right?

Aliquis
  • 2,091
  • 4
  • 21
  • 40

2 Answers2

0

A Linux "user thread" is a thread that

  • is managed by the operating system,
  • was created when user mode code (e.g., an application) called the clone system call,
  • executes both user mode code and kernel code on behalf of the application.

A Linux "kernel thread" is almost the same thing, but

  • It is created by the kernel for its own purposes, and
  • It only executes kernel-mode code,

I don't know if "user thread" and "kernel thread" have similar meanings in any other operating system.

A "green thread", in any operating system, is a thread that is managed entirely by a user mode process. The operating system is unaware of green threads, and there is no way for multiple green threads in the same process to run on different CPUs at the same time.

Solomon Slow
  • 25,130
  • 5
  • 37
  • 57
  • 1
    I often heard that a "user thread" is not managed by the OS, so scheduling by the OS can only be done for "kernel threads"? – Aliquis Dec 07 '17 at 19:05
  • There's nobody in charge of what "User Thread" means. If you are talking about Linux with a Linux kernel hacker, then "user thread" probably means what I said. If you are talking with somebody else about something else, then "user thread" may mean the same as "green thread", or it might mean the same as "client thread", or who knows what else? – Solomon Slow Dec 07 '17 at 19:21
0

You are getting locked up by terminology. Let me try to hopefully un-confuse you with new terminology.

There are THREADS (aka kernel threads) and there are SIMULATED THREAD (aka user threads and what I have never heard before green threads.

CPUs only knows about processes. A traditional process consisted of a single stream of execution (you could call that a THREAD) and an address space. The operating system can fool the CPU by creating multiple instruction streams (THREADS) that share the same address space.

In a modern operating system, a process consists of an address space and one or more streams of execution (THREADS). Because these are managed by the operating system kernel, they have been called "kernel threads,:

On a system that supports THREADS, a process consists of an address space and one or more instruction streams of execution (ie THREADS).

In ye olde days, operating systems only allowed one thread per process. And it was not even called a "thread." We just had processes. Then came along languages, such as Ada, that needed multi-threading. Because the operating system did not support threads, the threads were implemented in language support libraries. These libraries used timers to switch among different streams of execution. These libraries simulated threads. Operating system books call this method "user threads."

The big question is why this is a major topic at all in an operating system book. Either the operating system supports threads or it does not.

"User threads" are application level programming so there is no need to operating system books to cover them other than to say they exist when threads are not available.

You are suffering from a simple topic being made overly complex.

user3344003
  • 20,574
  • 3
  • 26
  • 62