1,065 views
1 votes
1 votes

Since every thread can access every memory address within the process’ address space, one thread can read, write, or even wipe out another thread’s stack.

I am not getting the above statement, stack is specific to a thread then how we can access other thread's stack through Process' address space? 

2 Answers

Best answer
3 votes
3 votes
Threads are lightwieight process . Each threads share same address space of process . There are some really great advanatges if we comapre threads as compared to process . Ecah threads have its own register , stack but they all share file and code section . Threads share address space . Even one thread can guide to other threads (ASSISTANCE ) which is not posiible in process .  Threads are found to be advanatgeous where we need to handle multiple request . eg in a client server  application  A server can make use of threads and handle multiple request with multiple threads at the same time . but along with this advanatges , we have only  1 disadvantges ,

it may happen that thread 1 may wirite on thread 2 stack ,-- PROTECTION IS VIOLATED . but this is a rare condition.

(NOTE : each threads have its own stack beacuse they are executing task which are independnt of each other so they need to store there execution history of there task on stack )
selected by
0 votes
0 votes

Different threads in a process are not quite as independent as different processes. All threads have exactly the same address space, which means that they also share the same global variables.

Refer :http://www.cs.vu.nl/~ast/books/mos2/sample-2.pdf 

Related questions