[Lab 1] shared memory synchronization

tobias.hamann
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 4. Okt 2010 15:58

[Lab 1] shared memory synchronization

Beitrag von tobias.hamann »

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.
Tobias Hamann, M.Sc.
Modeling and Analysis of Information Systems
Department of Computer Science, TU Darmstadt
http://www.mais.informatik.tu-darmstadt.de

z33ky
Neuling
Neuling
Beiträge: 7
Registriert: 17. Apr 2012 20:29

Re: [Lab 1] shared memory synchronization

Beitrag von z33ky »

I'm guessing that something akin to fflush/fsync is missing. Do you close the SMO on the child?

tobias.hamann
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 4. Okt 2010 15:58

Re: [Lab 1] shared memory synchronization

Beitrag von tobias.hamann »

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

JanH
Neuling
Neuling
Beiträge: 10
Registriert: 5. Okt 2010 00:11

Re: [Lab 1] shared memory synchronization

Beitrag von JanH »

Use the same close() function that was used to close the pipe file descriptors.

tobias.hamann
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 4. Okt 2010 15:58

Re: [Lab 1] shared memory synchronization

Beitrag von tobias.hamann »

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

tobias.hamann
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 4. Okt 2010 15:58

Re: [Lab 1] shared memory synchronization

Beitrag von tobias.hamann »

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

Antworten

Zurück zu „Archiv“