0
votes

I wrote two simple processes - client and server (in c++ - LINUX) that share the same memory, one that writes to it and the other only reads from it. (took the code from this website:

http://www.cs.cf.ac.uk/Dave/C/node27.html#SECTION002730000000000000000

The problem: I need to make sure that the second process doesn't read from a certain line/address while the other process is writing to it (but it can read from other lines/addresses).

for example, if the "server" is writing to lines 10-15, the "client" cannot access those lines, but it can read from the rest of the lines.

I know that I need to use semaphores, but I don't know how to combine it with shared memory. Any example code/ help on how to use semaphores?

Note: I used SystemV IPC and not POSIX.

Thanks in advance

1

1 Answers

0
votes

This 16 page document should help you understand and implement semaphores: http://see.stanford.edu/materials/icsppcs107/23-Concurrency-Examples.pdf