简体   繁体   English

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

[英]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? 线程是否也像进程一样维护自己的内核堆栈?

Yes threads have their own stacks and their own kernel stacks (eg 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. 当一个线程进行系统调用时,你陷入内核模式(从用户模式),你将参数传递给内核,检查参数,内核做它需要做的事情(在内核堆栈中),返回返回到线程的最终值,然后返回用户模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM