[interprocess] Best practice question on shared resources.
Hi there, I am writing a "server" that is capable of communicating data to many "clients". Because I am implementing different communication modes (async, sync), I need special methods to lock and unlock a managed shared memory segment. My question is how to store the mutex, semaphore and managed_shared_memory segment information that are required in the lock and unlock methods. I see different approaches to implement this on client side. 1. Open the resources in the constructor of the client. Save pointers to the resources as members. So it is possible to access the resources in every method of the client class without opening them every time. The problem is that I do not recognize if the resources were closed because they only throw on opening (using linux). 2. Open the resources in the functions. That means I have to create the resource objects every time the function is called. So I have a chance to recognize if the resources have been removed. But I think this will create some useless overhead. Has anybody implemented something similar to this. How would you handle the shared resources? Thanks in advance Moritz Illustration: 1. class client { client() { _mtx = new boost::interprocess::named_mutex(...); } void lock() { _mtx.lock() } boost::interprocess::named_mutex * _mtx; }; versus 2. class client { void lock() { boost::interprocess::named_mutex mutex(...); mutex.lock() } };
participants (1)
-
Moritz