构建执行管道的c++库
C++ library to build up execution pipeline
我一直在寻找c++中可重用的执行管道库(作业调度器库?)。我在Boost里找不到任何东西。所以我最终找到了两个候选人:
- google-concurrency-library
- libpipeline
我还缺其他候选人吗?有人用过吗?它们在并行io和多线程方面有多好?这些库似乎仍然缺少依赖项处理。例如,我不太清楚如何写这样的东西:
$ cat /dev/urandom | tr P Q | head -3
在这个非常简单的例子中,流水线从下往上走,当head
进程停止拉出时,第一个cat
进程停止执行。
然而,我不知道如何从多线程和并行io中获益,例如:
$ cat /raid1/file1 /raid2/file2 | tr P Q > /tmp/file3
我没有办法说:当8个处理器可用时,在7个线程上执行tr
。
您正在寻找的是一个数据流框架。管道是一种特殊形式的数据流,其中所有组件都有一个消费者和一个生产者。
Boost支持数据流,但不幸的是,我不熟悉Boost。链接:http://dancinghacker.com/code/dataflow/dataflow/introduction/dataflow.html
无论如何,您应该将组件编写为单独的程序并使用Unix管道。特别是,如果您的数据特征是(或可以轻松转换为)行/文本。
也可以选择编写自己的数据流。这并不难,特别是当您有限制时(我的意思是管道:1个消费者/1个生产者),您不应该实现完整的数据流框架。管道就是将某种函数绑定在一起,将一个函数的结果传递给下一个函数的参数。数据流框架是关于组件接口/模式和绑定技术的。(很有趣,我已经写过了)
我会给线程构建块http://threadingbuildingblocks.org/一个尝试。它是开源和跨平台的。维基百科的文章很好:http://en.wikipedia.org/wiki/Intel_Threading_Building_Blocks
我今天刚刚读了关于RaftLib的文章,它使用模板和类来创建称为"内核"的管道元素。除了并行数据流之外,它还支持像您所展示的Bash示例那样的串行管道。来自首页上的Hello world示例:
#include <raft>
#include <raftio>
#include <cstdlib>
#include <string>
class hi : public raft::kernel
{
public:
hi() : raft::kernel()
{
output.addPort< std::string >( "0" );
}
virtual raft::kstatus run()
{
output[ "0" ].push( std::string( "Hello Worldn" ) );
return( raft::stop );
}
};
int
main( int argc, char **argv )
{
/** instantiate print kernel **/
raft::print< std::string > p;
/** instantiate hello world kernel **/
hi hello;
/** make a map object **/
raft::map m;
/** add kernels to map, both hello and p are executed concurrently **/
m += hello >> p;
/** execute the map **/
m.exe();
return( EXIT_SUCCESS );
}
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- IPC使用多个管道和分支进程来运行Python程序
- 如何创建函数管道,以便函数一个接一个地运行?
- Gstreamer 管道从命令 lne 到 c 代码
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 将旧管道转换为现代 openGL 时出现问题
- 如何使用管道在父级和子级之间来回传递文件
- 在没有管理员权限的情况下连接到同一网络中的命名管道
- 如何测量管道延迟?
- 我如何使用此程序管道多个命令?C++
- 先进先出:一个进程永远不会从管道读取
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- 使用模板而不是虚拟方法的管道模式
- 我可以写入关闭的套接字并强制纠正损坏的管道错误吗?
- 在 Azure DevOps 构建管道中使用英特尔C++编译器为 Linux 环境构建C++代码
- Opencv GStreamer管道在Raspberry Pi 4上不起作用
- 阻塞管道连接命名管道不触发
- GLib-ERROR:为GWakeup创建管道:打开的文件太多
- 向 vulkan 管道添加额外的 UBO 会停止所有几何体渲染
- 在命名管道中发送标准::字符串流