- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试使用 boost thread futures .所以如图here我们可以得到 shared future来自 packaged task .
所以我在 linux 上尝试这样的功能:
template <class task_return_t>
void pool_item( boost::shared_ptr< boost::packaged_task<task_return_t> > pt)
{
boost::shared_future<task_return_t> fi= pt->get_future(); // error
//...
但调用它时出错:
../../src/cf-util/thread_pool.h: In member function ‘void thread_pool::pool_item(boost::shared_ptr<boost::packaged_task<R> >) [with task_return_t = void]’:
../../src/cf-util/thread_pool.h:64:3: instantiated from ‘void thread_pool::post(boost::shared_ptr<boost::packaged_task<R> >) [with task_return_t = void]’
../../src/cf-server/server.cpp:39:27: instantiated from here
../../src/cf-util/thread_pool.h:124:58: error: conversion from ‘boost::unique_future<void>’ to non-scalar type ‘boost::shared_future<void>’ requested
我之前没有从该任务中获取任何 future 。 all source code , place where I do call from , my thread pool that is being called .在 Visual Studio 2010 下的 Windows 上,它可以完美编译和运行。
我该怎么办?如何修复或绕过此错误?
最佳答案
从unique_future
到shared_future
的转换在the documentation 中使用了以下构造函数:
shared_future(unique_future<R> && other);
这使用右值引用来确保在源代码中清楚地表明您打算破坏“other”的值。 VC++2010 可能默认提供足够的右值引用支持以直接支持它,而您在 linux 上使用的编译器(可能是 gcc)需要一个额外的标志,如 -std=gnu++0x
支持它。如果没有那个标志,boost 会退回到“移动仿真”,这可能(我还没有检查过)需要你写:
boost::shared_future<task_return_t> fi = boost::move(pt->get_future());
关于C++, Linux : error: conversion from ‘boost::unique_future<void>’ to non-scalar type ‘boost::shared_future<void>’ requested. 如何绕过它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7251538/
我正在尝试为 Raspberry Pi 交叉编译一个大型项目。我正在使用由 crosstool-ng 构建的工具链,gcc 版本 4.7.3。当看到 std::shared_future 时,编译会停
Passing std::shared_future by value是合法的,因为 std::shared_future 是可复制的。 #include #include #include i
我找不到关于此事的直接确认或反驳。所有答案似乎都解决了“从多线程访问”方面的问题,而不是重复访问本身。 标准是否定义了 std::shared_future 的行为? boost::shared_fu
future 和 shared_future 有什么区别? 在什么情况下我们必须使用 shared_future 而不是 future? 我试图找到可以对比 C++11 的这两个特性的好的文档,但我在
一般问题: 是 std::shared_future::operator= atomic 吗? 例如 struct object { object() { sf = std::
我有一个 DAG 任务,我正在尝试使用 boost::shared_future 框架执行这些任务。 举个具体的例子,考虑图中的data flow graph。 下面是对此进行编码的尝试: #incl
Josuttis 指出 [“标准库”,第 2 版,第 1003 页]: Futures allow you to block until data by another thread is provi
我有一个线程从容器中获取每个元素并向数据库发送上传请求。上传是同步完成的。 容器中的元素是金融合约,它们可能有也可能没有与之关联的数据结构调用 ticktable。 现在,对于那些有 ticktabl
我对 Effective Modern C++ 的第 270 页有疑问,作者是 Scott Meyers。 第 5/6 行,他写道:“唯一的微妙之处在于每个 react 线程都需要引用共享状态的 st
我了解什么是 std::future 但我不了解何时以及如何使用 std::shared_future 和 std::promise,而且我在网上找不到很好的解释。 我会很感激一些帮助我解决这个问题。
C++标准库中的各种类都有成员交换函数,包括一些多态类,如std::basic_ios。 .模板类std::shared_future显然是一个值类型并且 std::future是一个只能移动的值类型
我尝试使用 boost thread futures .所以如图here我们可以得到 shared future来自 packaged task . 所以我在 linux 上尝试这样的功能: temp
我是一名优秀的程序员,十分优秀!