Shr*_*dha 7 c++ multithreading boost pthreads
我一直在使用pthreads库编程示例,因为我理解什么是多线程.最近我在互联网上遇到了Boost线程库并且很好奇.任何人都可以指出两者之间的显着差异吗?是否有来自Boost的额外特权,如果是,那么这些是什么?
How*_*ant 11
boost :: thread的设计受到pthreads的强烈影响,但当然被设计为C++库而不是C库.以下是我想到的一些差异.我并不认为这是一份详尽的差异清单.
事情pthreads有boost :: thread缺乏:
当你使用boost :: thread时,你可以通过调用成员函数来获取底层
pthread_t(或pthread_mutex_t等)native_handle(),并使用它来重新获得不是由boost :: thread直接提供的功能.
pthread_attr_setschedparam)pthread_attr_getstacksize)pthread_mutex_getprioceiling)事情boost :: thread有pthreads缺乏:
可以在pthreads中完成以下事情(在pthreads上实现boost :: thread之后).但是在pthreads中没有明确和直接的API来做这些事情.
根据我的经验,boost::thread 库具有与 pthread 密切相关的功能。pthread 中提供了一些在 boost::thread 库外部的东西,但在 boost 中仍然可用(例如 boost::interprocess 中提供的信号量)。
我看到的主要好处是能够[更]轻松地编写跨平台代码。由于 boost::thread 库似乎是作为各种操作系统原语的跨平台接口层实现的,因此我不相信 boost::thread 中可以找到在实际操作系统 API。
事实上,Windows 的一些底层功能我还没有找到真正的等价物,主要是根据我使用 Win32 的经验,并且几乎可以肯定是因为我对 boost::thread 中提供的内容的了解有限。和 pthread 库。
| 归档时间: |
|
| 查看次数: |
2979 次 |
| 最近记录: |