Two Linux processes open and mmap the same /dev/shm/ shared memory file and use it as common memory. Question: what is the simplest and best way for one process to "wake up" the other process to notify that it should look in the memory? For example, can one process cause a poll() event for the other process's file descriptor? The solution doesn't need to be portable but I would like it to be simple.
That's why POSIX has condition variables.
Define a shared POSIX condition variable and its associated mutex in the shared memory region.
Then have one thread wait on the condition variable and the other signal the condition variable event when it wants the other thread to look in the memory.
There's a lot of material on the web on condition variables. Here is one pretty good short one: https://computing.llnl.gov/tutorials/pthreads/#ConditionVariables
You may please consider using a semaphore (POSIX named semaphore) also to solve this.
One simple example, using shared Memory (In the example it is in System V, but you can use it with POSIX too) and POSIX semaphore is in the link , How can 2 processes talk to each other without pipe()?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With