Hi,
We are currently experiencing strange behaviour regarding Exercise 4 of the 1st lab assignment:
After opening the shared memory and truncating it, we fork a second process. The child mmaps the shared memory, writes to it and munmaps it again. The parent waits for the child to exit, mmaps the shared mem itself, reads from it and munmaps it again. This approach, however, succeeds only in some cases. The reading process fails to obtain any content from shared mem in many cases.
Are we misssing some important step here? Or is the write operation to the mmaped shared mem an asynchronous write? Adding a sleep() in the parent seems to solve the problem, after 100 msec the reading always succeeds.
Thanks in advance.
[Lab 1] shared memory synchronization
-
- Windoof-User
- Beiträge: 40
- Registriert: 4. Okt 2010 15:58
[Lab 1] shared memory synchronization
Tobias Hamann, M.Sc.
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
Re: [Lab 1] shared memory synchronization
I'm guessing that something akin to fflush/fsync is missing. Do you close the SMO on the child?
-
- Windoof-User
- Beiträge: 40
- Registriert: 4. Okt 2010 15:58
Re: [Lab 1] shared memory synchronization
We open the shm before forking and unlink it in the parent after read access. In the child process, we only mmap and shm and unmap it after writing to it. What exactly do you mean by closing it? There is no function like shm_close(), or at least I did'nt find one...
Tobias Hamann, M.Sc.
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
Re: [Lab 1] shared memory synchronization
Use the same close() function that was used to close the pipe file descriptors.
-
- Windoof-User
- Beiträge: 40
- Registriert: 4. Okt 2010 15:58
Re: [Lab 1] shared memory synchronization
Oh, good point, we did not think of that initially. However, that does not seem to make a difference either...
Tobias Hamann, M.Sc.
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
-
- Windoof-User
- Beiträge: 40
- Registriert: 4. Okt 2010 15:58
Re: [Lab 1] shared memory synchronization
With assistance by the teaching staff, we found the problem: there was a wait() missing in one of our functions. Thanks a lot for the help everyone.
Tobias Hamann, M.Sc.
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de