关于PPL是什么,可以搜索关键字MSDN PPL了解详情。这里谈一下困扰自己好一阵子的一个地方--task chain中抛出异常的处理,一来可为其他码农同行参考,二来给自己做个记录,以免日后忘却。

Value-based continuation的成功尝试

void testValueBasedContinuation()
{
concurrency::task<void> task1([] {
throw std::exception("Hello"); }); //set a breakpoint here, and see the wcout IS executed
auto task2 = task1.then([]() {
std::cout << "continuation" << std::endl;
}); try
{
task2.wait();
}
catch (std::exception& e)
{
std::cout << "exception" << std::endl;
}
}

这里的要点在于,value-based continuation中continuation task的执行一定是在previous task执行完成之后,因此将continuation task用try catch(T-C)保护起来即可。(个人猜测,value-based chain会在同一个线程中执行)

错误的写法包括:

  1. 直接将task1的声明用try catch保护起来
  2. 直接将auto task2一句用try catch保护起来

原因是,声明处并不是task的真正执行的地方,保护起来并没有作用

导致PPL库抛出如下异常

        ~_ExceptionHolder()
{
if (_M_exceptionObserved == )
{
// If you are trapped here, it means an exception thrown in task chain didn't get handled.
// Please add task-based continuation to handle all exceptions coming from tasks.
// this->_M_stackTrace keeps the creation callstack of the task generates this exception.
_REPORT_PPLTASK_UNOBSERVED_EXCEPTION();
}
}

Task-based continuation的成功尝试

void testTaskBasedContinuation()
{
concurrency::task<void> task1([] {
throw std::exception("Hello"); });
auto task2 = task1.then([](concurrency::task<void>& previous) {
previous.get();
std::cout << "continuation" << std::endl;
});
try
{
task2.wait();
}
catch (std::exception& e)
{
std::cout << "exception" << std::endl;
}
}

这里的关键是previous.get()那一行,保证代码会在那里抛出异常(而不是其他的线程,个人猜测).

Parallel Pattern Library(PPL)学习笔记的更多相关文章

  1. Parallel Programming for FPGAs 学习笔记(1)

    Parallel Programming for FPGAs 学习笔记(1)

  2. Enterprise Library 6 学习笔记

    今天是2014年上班第一天,想着今年要做点与往年不同的事情,就从写博客开始吧. 公司的项目一般都用微软的企业库,一直没时间好好研究,第一天上班还不忙,就抽空研究了下.搜索一下,发现这个企业库已经到了6 ...

  3. DPDK Mbuf Library(学习笔记)

    1 Mbuf库 Mbuf库提供了分配和释放缓冲区(mbufs)的功能,DPDK应用程序可以使用这些mbufs来存储消息缓冲. 消息缓冲存储在内存池中,使用Mempool库. 数据结构rte_mbuf通 ...

  4. R parallel包学习笔记2

    这个部分我在datacamp上面学习笔记,可视化的性能很差,使用的函数也很少. 可以参考一下大佬的博客园个人感觉他们讲的真的很详细 https://cosx.org/2016/09/r-and-par ...

  5. V-rep学习笔记:Reflexxes Motion Library 3

    路径规划 VS 轨迹规划 轨迹规划的目的是将输入的简单任务描述变为详细的运动轨迹描述.注意轨迹和路径的区别:Trajectory refers to a time history of positio ...

  6. V-rep学习笔记:Reflexxes Motion Library 2

    VREP中的simRMLMoveToPosition函数可以将静态物体按照设定的运动规律移动到指定的目标位置/姿态.If your object is dynamically enabled, it ...

  7. 【HLSL学习笔记】WPF Shader Effect Library算法解读之[DirectionalBlur]

    原文:[HLSL学习笔记]WPF Shader Effect Library算法解读之[DirectionalBlur] 方位模糊是一个按照指定角度循环位移并叠加纹理,最后平均颜色值并输出的一种特效. ...

  8. 【HLSL学习笔记】WPF Shader Effect Library算法解读之[Embossed]

    原文:[HLSL学习笔记]WPF Shader Effect Library算法解读之[Embossed] Embossed(浮雕效果)          浮雕效果主要有两个参数:Amount和Wid ...

  9. 【HLSL学习笔记】WPF Shader Effect Library算法解读之[BandedSwirl]

    原文:[HLSL学习笔记]WPF Shader Effect Library算法解读之[BandedSwirl] 因工作原因,需要在Silverlight中使用Pixel Shader技术,这对于我来 ...

随机推荐

  1. 通过u盘启动盘重装系统

    前言:一直想通过u盘启动盘给旧本装个win7,但是发现网上完整的教程很少.这里分享给大家我重装的一些步骤和遇到的问题. 前期准备: 1.我们要准备一个容量在4G以上的U盘. 2.我们要将U盘中的重要数 ...

  2. MapReduce Design Patterns(chapter 2(part 1))(二)

    随着每天都有更多的数据加载进系统,数据量变得很庞大.这一章专注于对你的数据顶层的,概括性意见的设计模式,从而使你能扩展思路,但可能对局部数据是不适用的.概括性的分析都是关于对相似数据的分组和执行统计运 ...

  3. January 07 2017 Week 1st Saturday

    Procrastination is the thief of time. 拖延乃是光阴之窃贼. My parents always tell me that things ought to be d ...

  4. December 31st 2016 Week 53rd Saturday

    In every triumph, there's a lot of try. 每个胜利背后都有许多尝试. This Year is over, and let it be. It would be ...

  5. 在Android Studio2.3中配置OpenCV4Android SDK

    在Android Studio2.3中配置OpenCV4Android SDK 一,OpenCV4Android下载地址 [2.4.11]http://onhdz331f.bkt.clouddn.co ...

  6. 使用SN.exe对.Net生成的程序集进行签名

    CLR用数字签名的方式防止程序集发布后被人篡改,也可以确定发布人,这个方法就是使用公/私钥对,然后对程序集所有模块取一个哈希生成一个数字签名放在程序集的元数据中. 1.创建公/私钥对     创建公/ ...

  7. nd.array.where

    http://mxnet.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.where Return the elements, eit ...

  8. Vue动态实现评分效果

    1.图片分为三种 on:half:  off <style> .star{ font-size: 0; } .star-item{ display: inline-block; backg ...

  9. CS 20_Overview of Tensorflow

    tf.assign(A, new_number): 这个函数的功能主要是把new_number的值向前传递给了A run( fetches, feed_dict=None, options=None, ...

  10. cocos2d-x开发: 完善接口范例分离模块

    在上一篇文章中,我阐述了一下为什么要做分离这种工作,这篇文章没什么重点,只是将上一次没有完善的工作做完.原本我想做到像Lua-tests那样子,能够一次完全显示所有的tests,然后选择要执行的tes ...