Sharing an address space means that for every virtual memory location, there is a single value right? Now, AFAIK, with threads, that would be true for the code, static data and heap, but the page table entries and even the top level page table has to be different for each thread since the stack section would be different for each thread. Am I wrong? Also at the end of the day, is a context switch between threads faster that that between 2 processes. I understand that there would be the cache affinity advantage since the non stack portion is the same, but apart from that, a thread switch seems to be just as costly as a process switch. Is that right?
Asked
Active
Viewed 56 times
0
-
Related: https://stackoverflow.com/questions/5440128/thread-context-switch-vs-process-context-switch – Omry Nov 14 '20 at 11:22
-
@Omry The answers there make the 'share the same address space' claim, which I highly doubt. – user2277550 Nov 14 '20 at 11:28
-
1And what reason do you have for doubting that? – Omry Nov 14 '20 at 11:30
-
Because the stack is part of the address space and is different for each thread. – user2277550 Nov 14 '20 at 11:35
-
The stack is indeed part of the address space, and is unique for each thread, but the address space is still shared. See https://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread and https://learn.microsoft.com/en-gb/windows/win32/procthread/about-processes-and-threads for more details. – Omry Nov 14 '20 at 11:39
-
If the stack is different and part of the adress space, that implies that the address spaces are different isn't it? Could you point me to a place which specifically addresses this point? – user2277550 Nov 14 '20 at 11:43
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224555/discussion-between-user2277550-and-omry). – user2277550 Nov 14 '20 at 11:46