I have the following scenario that I have working with a single client process and a single server process, but I am uncertain as to how to design to scale the number of servers.
Note, in what follows the servers and the single client are processes, not threads. I have an 2D 4x4 array matrix [0-based, row-major] in shared memory that I would like several servers to be able to update a given assigned cell. The diagonal entries are always = 1. So for example, for the sake of simplicty say there are three servers 1, 2, 3. I would like to assign server 1 to always write to cell [1,0], and and server 2 to always write to cell [2,0] and server 3 to always write to [3,0].
The client's job is just to copy the matrix from shared memory to a local copy so as to block the writers for as little time as possible. The question is:
In this scenario of multiple servers and one client, do I need a semaphore set for each of the cells? If so, how do I coordinate all the servers since only one can be writing at a time while the [client potentially being multi-threaded one thread per each cell] client copies the shared matrix locally? If instead I use a binary semaphore, and there are multiple servers writing to shared memory, which of the servers is signaled to allow the write since several servers and one client are sharing a single binary semaphore set? I realize that a multi-threaded program for example actors may work better, but I need the servers to be processes not threads.
A simple example in C++ suffices, or an explanation is good too.