Hi Zacharoni,
Quote:
I was thinking of having a structure in "Shared memory" where the slaves can access, and there is only one writer to the memory so I most likely wont need a semaphore. The data will be updated fairly slowly, once every minute for example.
Thinking that way is the best premise for troubles. You need to use semaphore, as long as the memory is accessed concurrently by 2 or more processes ( Ok, there are way to come without semaphore. But usually one starts with a semaphore - and only if there are some major performance bottlenecks - one turns to other more complicated synchronization algorithms that are "semaphore free" ),
Quote:
I have a structure in shared memory, how can I guarantee that the structure will be contiguous in memory? It is a requirement I must have.
By "contiguous" in memory, you mean that the structure fields can be accessed linearly from the structure's base address? Unless you have a self-referencing structure (like linked list, tree...), that should work. ( remember though, that the compiler can pad the structure, for instance due to alignment architecture requirements. But that's something you should cope with anyway I guess )
Quote:
The master program will have its own internal data structure that is being updated from the serial port, and then it will modify the data and send it out to a global structure that is in shared memory for the clients to use.
Should the client be aware when the data are updated by the master? Or are the clients reading the data asynchronously (e.g. at some later time) after the update?
Hope this helps,
/Lew