【发布时间】:2012-06-18 14:12:41
【问题描述】:
在愤怒中学习和使用提升共享内存一段时间后,我得出了一个心智模型,即何时使用哪种类型的互斥体,如下所示:
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
}
我希望我原则上没有弄错,所以如果是这样,请纠正我。我的意图是推进和纠正现有代码以及我自己的不符合这张图片但我想确定的代码。
这个问题的两个部分: 我认为它确实没问题,但使用 //2 毫无意义 - 在上下文中这不如 //1 好,但原因是什么?性能?
对于 //3,我猜对了吗?有人可以给出它不起作用的技术幕后原因,或者至少在什么情况下它不起作用?
【问题讨论】:
标签: c++ shared-memory boost-interprocess boost-mutex