Alex Rivera | Logout

Process VS thread : can two processes share the same shared memory ? can two threads?

Asked 2012-07-19T18:07:23.567
20

After thinking about the the whole concept of shared memory, a question came up:

Can two processes share the same shared memory segment? Can two threads share the same shared memory?

After thinking about it a little more clearly, I'm almost positive that two processes can share the same shared memory segment, where the first is the father and the second is the son, that was created with a fork(), but what about two threads?

Thanks

Edit
Report

1 Answer

2

Yes, two processes can both attach to a shared memory segment. A shared memory segment wouldn't be much use if that were not true, as that is the basic idea behind a shared memory segment - that's why it's one of several forms of IPC (inter-Process communication).

Two threads in the same process could also both attach to a shared memory segment, but given that they already share the entire address space of the process they are part of, there likely isn't much point (although someone will probably see that as a challenge to come up with a more-or-less valid use case for doing so).

answered 2012-07-19T18:17:37.927

Your Answer