开发者

What's the difference between a thread's stack and a process's stack

Do threads and processes both h开发者_运维技巧ave independent stacks? If the answer is yes, what's the difference between them? Thanks in advance!


Processes don't have a stack. Threads do. A process is typically an address space, some resources and one or more threads. The threads run the actual code of the process so they each have their own stack.

The wiki article on stacks has more information http://en.wikipedia.org/wiki/Call_stack


From what I know (and correct me if I'm wrong), each process is given its own memory space, which contains 3 segments : the text segement (i.e the program), the data segment (as far as as I know it's for global and static variables), the stack segment which contains a number of things like local variables, the functions' parameters, the address that a functioin should return to.

Each process may have one or more threads. The process's threads share the memory space of the process, they do not "possess" memories of their own, this makes them easy to create and to terminate.

Let's recapitulate : the process has his own stack, the thread doesn't have his own stack.

If I'm wrong about this feel free to correct me.

Actually Mr.Tanenbaum's book "operating systems" covers this issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜