Valhalla Legends Forums Archive | C/C++ Programming | [C++] Static member variables and shared memory

AuthorMessageTime
NeBuR
I've found a problem with class static member variables, while porting an application from monoprocess to multiprocess architecture, using shared memory as communication mechanism between related processes. With this approach, it's necessary to allocate in shared memory all those variables/objects which will be accessed from more than one process, no matter if in read, write or both modes. However, although I do that, it occurs that class static member variables are still allocated in main process heap, and duplicated when a fork() is done. So each process have its own private copy of satic member variables and, as consequence, changes made to those static variables in a process after the fork() point can't be visible for the others.

This is not correct, at least in my case, because the initialization of those static member variables must be done after the fork() point, and anyway they should be changeable in run-time at any moment, being those changes visiblefor all related processes. Does someone know any possible solution for this?
March 4, 2004, 2:37 PM
Kp
Don't make them a class static variable? :P From the description, you have data sharing working for some other type of variable, so why not store your static data that way instead?
March 4, 2004, 8:43 PM
Adron
Also, it would make much more sense to use threads if what you want to do is run multiple threads of execution with shared memory between them...
March 4, 2004, 11:44 PM

Search