techie11
techie11

Reputation: 1407

user threads v.s. kernel threads

Could someone help clarify my understanding of kernel threads. I heard that, on Linux/Unix, kernel threads(such as those of system calls) get executed faster than user threads. But, aren't those user threads scheduled by kernel and executed using kernel threads? could someone please tell me what is the difference between a kernel thread and a user thread other than the fact that they have access to different address spaces. what are other difference between them? Is it true that on a single processor box, when user thread is running, kernel will be suspended?

Thanks in advance,

Alex

Upvotes: 6

Views: 6064

Answers (1)

user149341
user149341

Reputation:

I heard that, on Linux/Unix, kernel threads(such as those of system calls) get executed faster than user threads.

This is a largely inaccurate statement.

  • Kernel threads are used for "background" tasks internal to the kernel, such as handling interrupts and flushing data to disk. The bulk of system calls are processed by the kernel within the context of the process that called them.

  • Kernel threads are scheduled more or less the same way as user processes. Some kernel threads have higher than default priority (up to realtime priority in some cases), but saying that they are "executed faster" is misleading.

Is it true that on a single processor box, when user thread is running, kernel will be suspended?

Of course. Only one process can be running at a time on a single CPU core.

That being said, there are a number of situations where the kernel can interrupt a running task and switch to another one (which may be a kernel thread):

  • When the timer interrupt fires. By default, this occurs 100 times every second.
  • When the task makes a blocking system call (such as select() or read()).
  • When a CPU exception occurs in the task (e.g, a memory access fault).

Upvotes: 9

Related Questions