Having now for a while been learning and using boost shared memory in anger I've arrived at a mental model, of when to use what type of mutex, that looks like this:
class IntendedToResideInProcessMemory {
boost::mutex mutex_for_this_process; // 1
boost::interprocess::interprocess_mutex
ok_but_pointless_to_use_interprocess_mutex_here; // 2
}
class IntendedToBeCreatedInSharedMemory {
boost::mutex bad_mutex_at_a_guess_this_will_allocate_something_on_heap;// 3
boost::interprocess::interprocess_mutex
good_for_multiprocess_shared_lock; // 4
}
I hope I haven't in principle got this wrong, so please correct me if so. My intention is to move forward and correct existing code as well as my own that does not conform to this picture but I want to be certain.
Two parts to this question: I assume it really is ok, but is pointless to use //2 - in the context this is less good than //1, but what are the reasons why? Performance?
For //3, is my guess right? Can someone give the technical behind-the-scenes reason why it will not work, or at least, in what circumstance it will not work?