小编ral*_*e01的帖子

asio 如何更改等待中的执行者?

我已阅读此问题并尝试使用以下代码复制答案:

#include <iostream>
#include <syncstream>
#include <thread>
#include <coroutine>
#include <boost/asio.hpp>
#include <boost/asio/experimental/as_single.hpp>
#include <boost/bind/bind.hpp>
#include <boost/thread/thread.hpp>

inline std::osyncstream tout() {
  auto hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
  return std::osyncstream(std::cout) << "T" << hash << " ";
}

namespace asio = boost::asio;

asio::awaitable<void> mainCo(asio::io_context &appIO, asio::io_context &prodIO) {
  // the thread should also change when using the IO contexts directly.
  auto astrand = asio::io_context::strand{appIO};
  auto pstrand = asio::io_context::strand{prodIO};

  tout() << "MC on APPIO" << std::endl;
  co_await asio::post(pstrand, asio::use_awaitable);
  tout() << …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-asio c++20 c++-coroutine

8
推荐指数
1
解决办法
1493
查看次数

asio中prefer,require和make_work_guard之间的区别

在下面的示例中,我为我的应用程序启动一个工作线程。后来我发布了一些作品。为了防止它过早返回,我必须确保“工作”出色。我使用 work_guard 对象来执行此操作。然而,我发现了另外两种“确保”工作的方法。我应该在整个申请过程中使用哪一个?有什么区别吗?

#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <syncstream>
#include <iostream>

namespace asio = boost::asio;

int main() {
  asio::io_context workerIO;
  boost::thread workerThread;
  {
    // ensure the worker io context stands by until work is posted at a later time
    // one of the below is needed for the worker to execute work which one should I use?
    auto prodWork = asio::make_work_guard(workerIO);
    // prodWork.reset(); // can be cleared
    asio::any_io_executor prodWork2 = asio::prefer(workerIO.get_executor(), asio::execution::outstanding_work_t::tracked);
    // prodWork2 = asio::any_io_executor{}; // can be cleared …
Run Code Online (Sandbox Code Playgroud)

c++ boost-asio asio

7
推荐指数
1
解决办法
1739
查看次数

"CPU OpenCL项目"与"GPU OpenCL项目"的区别

我安装了英特尔OpenCL SDK,我想创建一个项目.Visual Studio 2017向我展示了这两个选项和第三个"空OpenCL项目".我不知道两者之间有什么区别.我试着查看模板代码,但由于我(还)对OpenCL一无所知,我无法理解它们的区别.

许可证标题:

/*****************************************************************************
 * Copyright (c) 2013-2016 Intel Corporation
 * All rights reserved.
 *
 * WARRANTY DISCLAIMER
 *
 * THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, …
Run Code Online (Sandbox Code Playgroud)

c++ opencl

6
推荐指数
1
解决办法
136
查看次数

标签 统计

c++ ×3

boost-asio ×2

asio ×1

boost ×1

c++-coroutine ×1

c++20 ×1

opencl ×1