Question

It's a simple question but I can't wrap my head around a solution. I am running a program that is using shared memory. All it needs to do is check if there is new input in the shared memory location and then print out that string. It runs on an infinite loop and will only print out when there is new input.

I'm having trouble writing the IF condition which checks if a new string has been set.

Any help would be grateful. Thanks

Was it helpful?

Solution

You'll typically have a semaphore in addition to your shared memory. The process that writes to the shared memory sets the semaphore after writing data into the shared memory. The other process waits on the semaphore, and reads the data when the semaphore indicates that data is available. See sem_open, sem_wait, sem_post, and sem_close

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top