boostorg / boostorg/cobalt

Unhandled `cobalt::task` prevents destruction of `asio::io_context`

Open
#180 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
347
Forks
47
Avg merge
3d 8h
Merged PRs (30d)
1

Description

Code:
```c++
#include

#include
#include

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

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

cobalt::task 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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.