Will the shared memory be corrupted if two programs access it simultaneously, one writing into it and the other one reading from it?
I have two programs, one will get some data from servers and web and save parsed data into the shared memory, and i have a read program, that will read until the last saved data set.
For example, if the first program has collected data from 100 servers and is currently in the 101th server, all the data until the 100th server will be read by the reader program. Once 101th is finished, then reader program will read the 101th data set.
Here data set from a server may have multiple data, like disk space, load etc.
So does this kind of access corrupt the data in the shared memory? Or is it ok the way i do it?
What you have described is actually a common computing problem in concurrency called Readers-writers
If you try to read from the memory while other program is writing to it, you will most likely get corrupted data. You should use one of synchronization primitives (locks, semaphores, monitors…) to ensure this situation will never happen.
I recommend you to have a look at The Little Book of Semaphores, especially chapter 4.2 Readers-writers problem.