1

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;
};
brunoos
  • 81
  • 1
  • 2
  • 6
  • 2
    You can use boost interprocess message queues instead. Each party has it's own message queue. Server has a well known named queue. Clients send their requests adding the name of their message queue to it. The server then processes the request, and sends the result to the specific client using that client's message queue for that. Synchro is done for you. – Yury Korobkin Dec 17 '13 at 17:26
  • You could also use a (bost!) map in shared memory (`#include `) from client ID to value, but then you would need to synchronize manually, e.g. via mutex. – koraxkorakos Dec 25 '13 at 23:54
  • Thanks, I was able to implement this with separate message queues for each client – brunoos Jan 09 '14 at 05:09

0 Answers0