cat8162

cat8162

0个粉丝

2

问答

0

专栏

0

资料

cat8162  发布于  2017-09-01 17:02:11
采纳率 0%
2个问答
3404

Hi3519使用c++ future 模板问题

 
1,源码
#include
#include
#include
#include
#include
#include

std::uint32_t add(std::uint32_t a, std::uint32_t b)
{
  std::cout << "thread id = " << std::this_thread::get_id() << ", a = " << a << ", b = " << b << std::endl;
  if(std::numeric_limits::max() - a < b) {
    throw std::overflow_error("overflow_error");
  }
  return a + b;
}

int main()
{
  // 使用std::async启动异步操作并返回std::future对象
  std::future f1 = std::async(std::launch::async, add, 1ul, 2ul);
  // 通过std::future::get等待异步操作完成并取得返回值
  std::uint32_t sum1 = f1.get();
  std::cout << "thread id = " << std::this_thread::get_id() << ", sum1 = " << sum1 << std::endl;
  // 4000000000ul + 4000000000ul会抛出异常,异常会被延迟到std::future::get或std::future::wait时抛出
  std::future f2 = std::async(std::launch::async, add, 4000000000ul, 4000000000ul);
  try {
    std::uint32_t sum2 = f2.get();
    std::cout << "thread id = " << std::this_thread::get_id() << ", sum2 = " << sum2 << std::endl;
  }
  catch(const std::overflow_error& e) {
    std::cout << "thread id = " << std::this_thread::get_id() << ", e.what() = " << e.what() << std::endl;
  }
}

2,Ubuntu 上编译 g++ -o testfure2 testfuture2.cpp -std=c++11 -lpthread  通过,运行正常;

3,hisi3519 使用arm-hisiv600-linux-g++ -o testfure2 testfuture2.cpp -std=c++11 -lpthread

testfuture2.cpp: In function ‘int main()’:
testfuture2.cpp:20:32: error: variable ‘std::future f1’ has initializer but incomplete type
     std::future f1 = std::async(std::launch::async, add, 1ul, 2ul);
                                ^
testfuture2.cpp:20:81: error: invalid use of incomplete type ‘class std::future
     std::future f1 = std::async(std::launch::async, add, 1ul, 2ul);
                                                                                 ^
In file included from testfuture2.cpp:2:0:
/opt/hisi-linux/x86-arm/arm-hisiv600-linux/arm-hisiv600-linux-gnueabi/include/c++/4.9.4/future:114:11: error: declaration of ‘class std::future
     class future;
           ^
testfuture2.cpp:25:32: error: variable ‘std::future f2’ has initializer but incomplete type
     std::future f2 = std::async(std::launch::async, add, 4000000000ul, 4000000000ul);
                                ^
testfuture2.cpp:25:99: error: invalid use of incomplete type ‘class std::future
     std::future f2 = std::async(std::launch::async, add, 4000000000ul, 4000000000ul);
                                                                                                   ^
In file included from testfuture2.cpp:2:0:
/opt/hisi-linux/x86-arm/arm-hisiv600-linux/arm-hisiv600-linux-gnueabi/include/c++/4.9.4/future:114:11: error: declaration of ‘class std::future
     class future;
           ^
出现以上错误!?

大侠帮忙看看?跪等!
我来回答
回答0个
时间排序
认可量排序
易百纳技术社区暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
相关问答
无更多相似问答 去提问
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区