用户和内核模式中的线程(Threads in User and kernel mode)

编程入门 行业动态 更新时间:2024-10-11 07:26:26
用户和内核模式中的线程(Threads in User and kernel mode)

线程在用户模式下运行并在内核模式下运行是什么意思? 这与用户模式的线程执行指令和内核模式的线程执行指令有关吗? 请详细说明。 另外,如果一个线程在用户模式下执行被置于挂起状态,它是否可能开始在内核模式下执行? 如果是的话,怎么可能呢? 到目前为止,我只知道一个线程如果被挂起将完全被SUSPENDED,即上下文切换将由CPU进行以安排另一个线程。

what do we mean by thread running in User mode and running in kernel mode? Is this related to thread execution instruction from User mode and thread executing instruction from Kernel mode? Kindly elaborate. Also, is it possible that if a thread is executing in user mode is put to suspended state, then it may start executing in kernel mode? if yes, how is it possible? Until now I am only aware that a thread if suspended will be SUSPENDED completely, i.e. the context switch will take place by CPU to schedule another thread.

最满意答案

线程在用户模式下运行并在内核模式下运行是什么意思?

无法通过没有上下文的短语来了解一个人的意思。 如果我不得不猜测,我会说他们正在谈论线程是由用户空间调度程序还是内核调度程序调度的。 但也有可能他们实际上在询问线程是运行用户代码还是内核代码。

这与用户模式的线程执行指令和内核模式的线程执行指令有关吗? 请详细说明。

它可能是。 它也可能不是。 没有背景,没有办法知道一个人的意思是什么。

另外,如果一个线程在用户模式下执行被置于挂起状态,它是否可能开始在内核模式下执行? 如果是的话,怎么可能呢?

对于内核调度线程的实现,调度程序在内核空间中运行。 实际挂起线程的代码通常也在内核空间中运行,因为它必须将线程添加到各种内核调度程序数据结构中。 因此,恢复线程的线程也将在内核空间中运行。 在更高级别的视图中,相同的执行线程可以“成为”内核调度程序,选择要执行的用户空间线程,然后“成为”该线程。

到目前为止,我只知道一个线程如果被挂起将完全被SUSPENDED,即上下文切换将由CPU进行以安排另一个线程。

对,那是内核代码。 所以同一个核心运行用户空间代码,然后运行内核代码,然后它运行另一个线程的用户空间代码。

what do we mean by thread running in User mode and running in kernel mode?

There is no way to know what a person means by a phrase without context. If I had to guess, I'd say they are talking about whether the thread is scheduled by a user-space scheduler or a kernel scheduler. But it's also possible they are actually asking whether the thread is running user code or kernel code.

Is this related to thread execution instruction from User mode and thread executing instruction from Kernel mode? Kindly elaborate.

It could be. It also might not be. There's no way to know what a person means by a phrase without context.

Also, is it possible that if a thread is executing in user mode is put to suspended state, then it may start executing in kernel mode? if yes, how is it possible?

For implementations where the kernel schedules threads, the scheduler is running in kernel space. The code that actually suspends the thread typically runs in kernel space too because it has to add the thread to the various kernel scheduler data structures. So the thread that resumes the thread will run in kernel space too. At a higher level view, the same thread of execution can "become" the kernel scheduler, choose a user-space thread to execute, and then "become" that thread.

Until now I am only aware that a thread if suspended will be SUSPENDED completely, i.e. the context switch will take place by CPU to schedule another thread.

Right, and that's kernel code. So the same core is running user space code, then it's running kernel code, then it's running the user space code of another thread.

更多推荐

本文发布于:2023-07-14 19:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   内核   模式   用户   kernel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!