Subj : Re: Function pointers in shm shared memory ? To : comp.programming.threads From : Uenal Mutlu Date : Sun May 01 2005 05:23 am "CM" wrote > > In the process of seekeing the most > effective clientserver communication > for a personal project i stumble about > an idea. > > under linux 2.6 > > Is it possible to share a memory segment > which would contain a block of function > that call inside the server process. > > the client after obtaining the shared memory > segment would just have to call a function in > shared segment to actually call a function of > the server > > > to clarify: > > Server: > Fct1() > { > // Some locking for multiple client possibility > // Do the actual work > // Unlocking > } > > shared segment: > BridgeFct1() > { > Fct1(); // Call the actual server function > } > > > Client: > > main() > { > fct = GetShared segment > > // Cast fct in function pointer > BridgeFct(); // Call the function in shared segment wich then will call > working function in server > } > > Any thought about this mechanism ? Code put in shared libraries (DLL) can be shared by any app loading the DLL (which usually is loaded automatically). For data you would define a shared segment inside the DLL, and again all applications would share the same data. You just would need to add an access synchronization mechanism if multiple processes and/or threads are going to access the shared data at the same time. This is simple to realize by using atomic counter (or flag) defined in the shared data segment, or using CriticalSection again it's data put in the shared data segment, or using a mutex if there is more than one process. There are also similar methods in Pthreads library. .