Previous | Next --- Slide 28 of 63
Back to Lecture Thumbnails
potato

Is the shared address space model only used for threads within the same process (so they already share an address space)? Security concerns aside, is it possible to have a shared address space across processes?

kostun

@potato One idea which comes to mind when you talk about sharing an address space across processes is mmap. In mmap's man page there is talk about the MAP_SHARED flag. For the lazy (and interested), here's the part about MAP_SHARED:

Share this mapping. Updates to the mapping are visible to other processes mapping the same region, and (in the case of file-backed mappings) are carried through to the underlying file. (To precisely control when updates are carried through to the underlying file requires the use of msync(2).)

So I think the shared address space model extends to different processes!

potato

@kostun Thank you! This also reminds me of DMA for communicating with hardware subsystems.

swkonz

How does memory access work for independent threads within the same program? I understand that generally when we fork a process we copy all the memory of the parent process. For threads, my thinking is that they do not have memory access to their parent unless they have explicitly been given access to a pointer. I'm just unsure about exactly how to think about what memory operations are happening under the hood during thread creation.

yayoh

@swkonz, forking is much more heavyweight than spawning a new thread. When you fork, each process has its own virtual memory address, as you mention. For threads, though, the call stack is the only non-shared memory segment. But, you could get a pointer to a stack from another thread and still access it if you really wanted to. Part of why spawning a thread is more efficient than spawning a task is because there are far fewer memory operations happening under the hood because so much is shared.

Please log in to leave a comment.