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

problems of co_composed on release mode #1413

Closed
zhllxt opened this issue Jan 19, 2024 · 0 comments
Closed

problems of co_composed on release mode #1413

zhllxt opened this issue Jan 19, 2024 · 0 comments

Comments

@zhllxt
Copy link

zhllxt commented Jan 19, 2024

#include <asio.hpp>
#include <asio/experimental/co_composed.hpp>

using tcp_socket = asio::as_tuple_t<asio::use_awaitable_t<
	>>::as_default_on_t<asio::ip::tcp::socket>;

std::string url_encode(std::string_view url)
{
	std::string r;
	r.reserve(url.size() * 2);
	return r;
}

struct async_request_op
{
	auto operator()(auto state) -> void
	{
		std::string_view url = "abc";
		url_encode(url);
		co_return asio::error_code{};
	}
};

template<
	typename SendToken = typename asio::default_completion_token<
	typename tcp_socket::executor_type>::type>
inline auto async_request(
	const auto& executor,
	SendToken&& token = typename asio::default_completion_token<
	typename tcp_socket::executor_type>::type())
{
	return asio::async_initiate<SendToken, void(asio::error_code)>(
		asio::experimental::co_composed<void(asio::error_code)>(
			async_request_op{ }, executor),
		token);
}

asio::awaitable<void> do_request()
{
	co_await async_request(co_await asio::this_coro::executor);
}

int main()
{
	asio::io_context ctx;
	asio::co_spawn(ctx.get_executor(), do_request(), asio::detached);
	ctx.run();
}

under release mode, it will cause crash:

002

001

This is just a simple example, and I want to demonstrate this problem through this example.

In fact, I encountered many similar problems while using co_composed. There was no problem in debug mode, but there were problems in release mode. I adjusted the compilation parameters, mainly parameters ‘inline function expansion’ and ‘enable intrinsic functions’, which sometimes solved the problem but sometimes couldn't.

@zhllxt zhllxt closed this as completed Jul 16, 2024
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