Summer_More_More_Tea
Summer_More_More_Tea

Reputation: 13356

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

Do threads and processes both have independent stacks? If the answer is yes, what's the difference between them? Thanks in advance!

Upvotes: 6

Views: 1014

Answers (2)

S.E.K.
S.E.K.

Reputation: 177

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.

Upvotes: -1

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

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

Upvotes: 7

Related Questions