每个线程都有自己的堆栈吗?

时间:2020-12-01 20:56:59

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?

当我从一个进程创建多个线程时,每个线程是否都有自己的堆栈,或者它们是否共享其父进程的堆栈。当线程进行系统调用时会发生什么?线程是否也像进程一样维护自己的内核堆栈?

1 个解决方案

#1


10  

Yes threads have their own stacks and their own kernel stacks (e.g. linux).

是的线程有自己的堆栈和内核堆栈(例如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.

当一个线程系统调用,你陷阱到内核模式(从用户模式),您将参数传递给内核,检查参数,内核w / e它需要做(在内核堆栈),返回最后一个值回你回到用户模式的线程和。

#1


10  

Yes threads have their own stacks and their own kernel stacks (e.g. linux).

是的线程有自己的堆栈和内核堆栈(例如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.

当一个线程系统调用,你陷阱到内核模式(从用户模式),您将参数传递给内核,检查参数,内核w / e它需要做(在内核堆栈),返回最后一个值回你回到用户模式的线程和。