每个线程都有自己的堆栈吗? [英] Does each thread have its own stack?
问题描述
当我从一个进程创建多个线程时,每个线程是否都有自己的堆栈,或者它们共享父进程的堆栈.线程进行系统调用时会发生什么?线程也像进程一样维护自己的内核堆栈吗?
When I create multiple threads from a process, then does each thread have its own stack, or is it that they share the stack of their parent process. What happens when a thread makes a system call? Do threads also maintain their own kernel stack like processes?
推荐答案
是的,线程具有自己的堆栈和内核堆栈(例如linux).
Yes threads have their own stacks and their own kernel stacks (e.g. linux).
当线程进行系统调用时,您陷入了内核模式(从用户模式进入),将参数传递给内核,对参数进行了检查,内核确实需要执行(在内核堆栈中)),将最终值返回给线程,然后返回用户模式.
When a thread makes a system call, you trap into kernel mode (from user mode), you pass the arguments to the kernel, the arguments are checked, the kernel does w/e it needs to do (in the kernel stack), returns the final value back to the thread and you go back to user mode.
这篇关于每个线程都有自己的堆栈吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!