Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled cobalt::task prevents destruction of asio::io_context #180

Open
Lyulf opened this issue May 13, 2024 · 1 comment
Open

Unhandled cobalt::task prevents destruction of asio::io_context #180

Lyulf opened this issue May 13, 2024 · 1 comment

Comments

@Lyulf
Copy link

Lyulf commented May 13, 2024

Code:

#include <cstdio>

#include <boost/asio.hpp>
#include <boost/cobalt.hpp>

namespace asio = boost::asio;
namespace cobalt = boost::cobalt;

asio::awaitable<void> emptyAsioAwaitable()
{
  std::puts("Inside ASIO");
  co_return;
}

cobalt::task<void> emptyCobaltTask()
{
  std::puts("Inside COBALT");
  co_return;
}

void testCobalt()
{
  asio::io_context context;
  cobalt::spawn(context, emptyCobaltTask(), asio::detached);
  context.stop();
}

void testAsio()
{
  asio::io_context context;
  asio::co_spawn(context, emptyAsioAwaitable(), asio::detached);
  context.stop();
}

int main()
{
  std::puts("before ASIO test");
  testAsio();
  std::puts("after ASIO test");

  std::puts("before COBALT test");
  testCobalt();
  std::puts("after COBALT test");
  return 0;
}

Built on Windows 10 64-bit using MSVC 17.9.6 (cl version 19.39.33523 for x64) with following command:

cl /Femain.exe main.cpp /nologo /external:IC:\Users\chodorowskip\repo\deps\vc143\boost-1.85.0\include\boost-1_85 /std:c++20 /MD /Z7 /O2 /EHsc /D_WIN32_WINNT=0x0601 /W4 /external:W0 /link /PROFILE /LIBPATH:C:\Users\chodorowskip\repo\deps\vc143\boost-1.85.0\lib libboost_cobalt-vc143-mt-x64-1_85.lib

Gives following result:

before ASIO test
after ASIO test
before COBALT test
@Pele44
Copy link

Pele44 commented May 13, 2024

With gcc 13.2 and clang 17.0.6, running under Fedora 39 (x86_64), problem doesn't occur. But running under Windows, example built by MSVC 19.39 get's stuck on io_context dcor...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants