为提升IPC什么好处呢? [英] Is Boost IPC any good?

查看:361
本文介绍了为提升IPC什么好处呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于跨平台的IPC我的默认选择是提升,但我看到它在两个不同的论坛上批评了,当我问一下,这涉及我。或许这只是一个巧合,那么,在提升IPC的想法和选择,一般一个跨平台的C ++库IPC?

有关的Windows开发我们使用VC参考++ 2008。

编辑:这里是我见过的做注释的例子(无法找到他们现在没事​​了):


  

对于提振,这是废话。至少在
  视窗。互斥不使用WinAPI的,
  相反,他们创建自己的
  基于文件的实现(WinAPI的=
  内核对象)。如果你的程序
  崩溃的文件不会被删除。
  您PROGRAMM启动下一次
  互斥无法创建的,因为
  现有的文件。



解决方案

从我与Boost.Interprocess中有限的经验,我没有什么大问题,但我真的不能表现发表评论。虽然这是真的,它并使用创建了程序的文件夹之外做的东西的文件,他们都应该是内存映射其中大部分否定的性能问题。在任何情况下,当你使用IPC你应该总是期待一些额外的性能开销。

至于你强调了批评,可以删除命名的互斥体或一直留任何其他命名资源由previous过程躺在附近(见静态的 删除(为const char *) 功能)。公平地说,这取决于你的应用程序,它可能会非常棘手正确使用这是不是你要处理一些使用Windows API时。另一方面,在Windows API是不可移植的。我的猜测是,他们使用的文件(即使存在更好的选择),以确保在不同的平台一致库的界面和行为。

反正命名互斥是什么样的库只提供很小的一部分。其中一个比较有用的功能是,它提供了<一个href=\"http://www.boost.org/doc/libs/1_44_0/doc/html/interprocess/quick_guide.html#interprocess.quick_guide.qg_named_interprocess\"相对=nofollow>自己的内存经理共享内存区域包括<一个href=\"http://www.boost.org/doc/libs/1_44_0/doc/html/interprocess/quick_guide.html#interprocess.quick_guide.qg_interprocess_map\"相对=nofollow> STL分配器。我个人觉得更愉快的工作与高层次的构造函数,然后它提供了原始内存。


更新:我没有更多一些Boost文档中挖,我在各种有趣的TID位传来:

此页面给多一点关于实施和图书馆的表演,但细节不包括实现原理。

<一个href=\"http://www.boost.org/doc/libs/1_46_0/doc/html/interprocess/acknowledgements_notes.html#interprocess.acknowledgements_notes.future_improvements.win32_sync\"相对=nofollow>这个链接明确指出,他们的Windows互斥的实现可以使用一些工作(版本1.46)。如果您在升压\\间\\同步文件夹挖远一点,你会发现一个名为两个文件夹 POSIX 模拟。这两个包含用于同步原语的实现细节。对于POSIX实施 interprocess_mutex ::锁定是你期望什么,但仿真的实现是pretty基本的:

  //与Boost 1.40服用。
内嵌无效interprocess_mutex ::锁(无效)
{
   做{
      提高:: uint32_t的prev_s =细节:: atomic_cas32(const_cast会&LT;提高:: uint32_t的*&GT;(安培; M_S),1,0);      如果(== M_S 1安培;&安培; prev_s == 0){
            打破;
      }
      //放弃当前的时间片
      细节:: thread_yield();
   }而(真);
}

因此​​,通过它的外观,他们的目的是对POSIX的支持和blobbed一切成使用内存映射文件的仿真层。如果你想知道他们为什么不提供一个专门的Windows实现,那么我建议,要求Boost邮件列表(我找不到在doc任何东西)。

My default choice for cross-platform IPC would be boost, but I saw it criticised in two different forums when I asked about it and this concerned me. Perhaps this was simply a coincidence, so what are the thoughts on boost IPC and choosing a cross-platform C++ IPC library in general?

For Windows dev we're using VC++ 2008 for reference.

edit: here is an example of comments I've seen made (can't find them all right now):

for boost, it's crap. At least on windows. The Mutexes don't use WinAPI, instead they create it's own File-Based implementation (WinAPI = Kernel-Objects). If your Program crashes the files won't be deleted. Next time your Programm is launched the mutex can't be created, because of the existing file.

解决方案

From my limited experience with Boost.Interprocess, I didn't have any major problems but I can't really comment on performance. While it's true that it does use files created outside of your program's folder to do its stuff, they should all be memory mapped which negates most of the performance problems. In any case, when you're using IPC you should always expect some extra performance overhead.

As for the criticism you highlighted, it is possible to remove a named mutex or any other named resources that has been left lying around by a previous process (see the static remove(const char*) function). To be fair, depending on your application, it might be tricky to use correctly which is not something you have to deal with when using the Windows API. On the other hand, the Windows API isn't portable. My guess is that they use files (even when better alternative exists) to keep the interface and behaviour of the library consistent across different platforms.

Anyway, named mutexes is only small part of what the library provides. One of the more useful features is that it provides its own memory managers for the shared memory region which includes STL allocators. I personally find it more pleasant to work with the high level constructs it provides then with raw memory.


UPDATE: I did some more digging the in the Boost documentation and I came across various interesting tid bits:

This page gives a bit more detail about the implementation and the performances of the library but doesn't include an implementation rationale.

This link clearly states that their Windows mutex implementation could use some work (version 1.46). If you dig a little further in the boost\interprocess\sync folder, you'll notice two more folders named posix and emulation. Both of these contains the implementation details for the synchronisation primitive. The posix implementation for interprocess_mutex::lock is what you'd expect but the emulation implementation is pretty basic:

// Taken from Boost 1.40.
inline void interprocess_mutex::lock(void)
{
   do{
      boost::uint32_t prev_s = detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);

      if (m_s == 1 && prev_s == 0){
            break;
      }
      // relinquish current timeslice
      detail::thread_yield();
   }while (true);
}

So by the looks of it, they aimed for Posix support and blobbed everything else into an emulation layer which uses memory mapped files. If you want to know why they don't provide a specialised Windows implementation then I suggest asking the Boost mailing list (I couldn't find anything in the doc).

这篇关于为提升IPC什么好处呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆