首页 > 解决方案 > 使用 C++ AMP 的退出代码中的问题

问题描述

环境:Visual Studio 2017,Windows 10 版本。1709.编译方式:发布。

当我打电话时:

accelerator_view acc_view = accelerator().default_view;

引发异常(请参见下图链接),但之后代码执行良好。但是当可执行进程退出并且我调用时:

::GetExitCodeProcess(hChildProcess, &retVal);

从调用者进程中,它不是返回 0,而是在 retVal 中返回一个垃圾值。挖掘源代码,问题似乎出在下面的代码片段中(SchedulerBase.cpp,第 149 行)

    // Auto-reset event that is not signalled initially
    m_hThrottlingEvent = platform::__CreateAutoResetEvent();

    // Use a trampoline for UMS
    if (!RegisterWaitForSingleObject(&m_hThrottlingWait, m_hThrottlingEvent, SchedulerBase::ThrottlerTrampoline, this, INFINITE, WT_EXECUTEDEFAULT))
    {
        throw scheduler_resource_allocation_error(HRESULT_FROM_WIN32(GetLastError()));
    }

我认为修复它超出了我的能力范围,因为上面的代码在 MFC 中。使用 Visual Studio 2013 编译时,相同的代码运行良好。请参阅堆栈的附图,显示我调用时引发的异常(并在内部捕获)

 accelerator_view acc_view = accelerator().default_view;

问题:如何在退出之前清理 AMP 并在调用 GetExitCodeProcess() 时获得正确的结果?

下图: 堆栈调用加速器().default_view

标签: c++-amp

解决方案


解决了!如果你添加

concurrency::amp_uninitialize();

使用AMP框架后,调用者进程调用时

::GetExitCodeProcess(hChildProcess, &retVal);

retVal参数填写正确。


推荐阅读