Reputation: 1591
As we all know in case of multiple threads each thread maintains it's separate stack and register state.
do they also maintain separate virtual memory state or it can be shared ?
I don't think there should be any problem in sharing virtual memory state between processes.
EDIT :
If thread doesn't maintain state then why not the third option of question 1 on the link ( http://www.geeksforgeeks.org/archives/19913 ) is not true ?
Upvotes: 0
Views: 2141
Reputation: 3158
They invariably share memory. And it can and does cause a lot of problems.
(Check the "multithreading" tag, for starters.) But multiple threads let you listen for lots of different input, and they let you make all those CPU cores earn their keep.
Upvotes: 0
Reputation: 206606
Each process has its own address space aka range of virtual addresses that the process can access. Each process can have multiple threads. So, yes all the threads in a process share the same address space. Note that this is the primary reason that variables can be shared across multiple threads of the same process without any special mechanism.
On the other hand one cannot share variables across two separate processes without using special mechanisms like Inter process communication because each process has its own address space.
Upvotes: 4
Reputation: 6585
Correct, two threads can share the same virtual memory space. This is essentially (very superficially) the definition of threads as they relate to processes.
Upvotes: 0