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

cobalt::thread doesn't release mutex #165

Open
Lyulf opened this issue Mar 22, 2024 · 0 comments
Open

cobalt::thread doesn't release mutex #165

Lyulf opened this issue Mar 22, 2024 · 0 comments

Comments

@Lyulf
Copy link

Lyulf commented Mar 22, 2024

Following code:

#include <boost/cobalt.hpp>

namespace cobalt = boost::cobalt;

cobalt::thread emptyThread()
{
  co_return;
}

int main(int /*argc*/, char** /*argv*/)
{
  auto thread = emptyThread();
  thread.join();
  return 0;
}

Built on Windows 10 64-bit using MSVC 17.9.0 (cl 19.39.33519 for x64) with following command:
cl /Femain.exe main.cpp /std:c++20 /MDd /EHsc -D_WIN32_WINNT=0x0601 /external:W0 /external:IC:\Users\chodorowskip\repo\deps\vc143\boost-1.84.0\include\boost-1_84 /link /DEBUG /LIBPATH:C:\Users\chodorowskip\repo\deps\vc143\boost-1.84.0\lib libboost_cobalt-vc143-mt-gd-x64-1_84.lib

Call aborts and gives following error message in console:
D:\a\_work\1\s\src\vctools\crt\github\stl\src\mutex.cpp(49): mutex destroyed while busy

This error doesn't seem to happen when thread is suspended at least once. For example using the following code:

#include <coroutine>

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

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

struct Awaitable
{
  bool await_ready()
  {
    return false;
  }
  template <typename Promise>
  void await_suspend(std::coroutine_handle<Promise> handle)
  {
    auto executor = handle.promise().get_executor();
    auto h = cobalt::unique_handle<void>(handle.address());
    asio::post(executor, std::move(h));
  }
  void await_resume() {}
};

cobalt::thread emptyThread()
{
  co_await Awaitable{};
}

int main(int /*argc*/, char** /*argv*/)
{
  auto thread = emptyThread();
  thread.join();
  return 0;
}
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

1 participant