I'm writing a server client application which I want to implement using boost interprocess shared memory APIs. The client process writes an integer key into shared memory and server reads that key, do some work and writes result variable is same shared memory. I've multiple client processes and a single server process running at a time.
The problem comes when client processes start reading the result then it don't know whether the it is the result for its corresponding key or not. It ends up reading result of different child process. So, I want to know is there any synchronization technique available in boost which can tell the child process to read only when its corresponding result is available in shared memory. Right now I'm using semaphores for synchronization
struct shared_memory_buffer {
shared_memory_buffer(): writer(1), reader(0), key(0){}
interprocess_semaphore writer, reader;
int key;
int result;
};