Seite 1 von 1

[Lab 1] shared memory synchronization

Verfasst: 8. Nov 2013 19:11
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.

Re: [Lab 1] shared memory synchronization

Verfasst: 9. Nov 2013 23:54
von z33ky
I'm guessing that something akin to fflush/fsync is missing. Do you close the SMO on the child?

Re: [Lab 1] shared memory synchronization

Verfasst: 10. Nov 2013 15:53
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...

Re: [Lab 1] shared memory synchronization

Verfasst: 10. Nov 2013 16:14
von JanH
Use the same close() function that was used to close the pipe file descriptors.

Re: [Lab 1] shared memory synchronization

Verfasst: 11. Nov 2013 13:18
von tobias.hamann
Oh, good point, we did not think of that initially. However, that does not seem to make a difference either...

Re: [Lab 1] shared memory synchronization

Verfasst: 11. Nov 2013 18:58
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.