zwilling@barney.cs.wisc.edu (Mike Zwilling) (10/03/89)
I have a question on sharing memory between task. I want multiple programs to share a common data structure. Each program in this problem is very different except for the need to access this common data structure, therefore I want each program to run as a separate task. From reading documentation, the steps to do this are: 1. Start a parent task that vm_allocate's the common data structure 3. Parent uses vm_inherit to set the inheritance properties 3. Parent task forks a child task 4. Child task performs an exec to start a program My question is: After step 4, how does the child get a pointer to the common data structure in virtual memory? Can this pointer be passed in a message? Pointers do not seem to be valid message types. An obvious solution to the entire problem would be to create a Mach server for the data structure and access the structure through RPC's. But, I'm trying to eliminate the RPC overhead since the data structure will not be shared across machines. I will summarize to the net any email responses. Thanks in advance for any help. ---- -- Mike Zwilling University of Wisconsin -- Madison Computer Sciences Dept. 1210 W. Dayton St. Madison, WI 53706
Richard.Draves@CS.CMU.EDU (10/03/89)
> Excerpts from netnews.comp.os.mach: 2-Oct-89 Sharing memory between > tasks Mike Zwilling@barney.cs. (1240) > From reading documentation, the steps to do this are: > 1. Start a parent task that vm_allocate's the common data structure > 3. Parent uses vm_inherit to set the inheritance properties > 3. Parent task forks a child task > 4. Child task performs an exec to start a program After step 3, the parent and child tasks are sharing the region of memory. The problem is that an exec system call throws away the caller's address space and builds a new address space. The child loses the shared region of memory. Two possibilities come to mind. First, Mach 2.5 supports external memory management. Among other things, this allows unrelated tasks to share memory objects. Mach 2.5 comes with the netmemoryserver program, which in fact allows tasks on different machines to share a memory object, with correct read/write semantics. However, you don't have to take advantage of that; the tasks sharing a region of memory can be on the same machine. Second, you could write/obtain a user-level program loader, and use it instead of exec to start the new program. You could tell/hack it to leave the inherited region of shared memory untouched. I know there are program loaders kicking around CMU. I don't know if there are any that don't rely on Mach 2.5 features. Rich