jthread icon indicating copy to clipboard operation
jthread copied to clipboard

[Q] Explicitly supplied stop_token in ctor results in (maybe) surprising result from get_stop_token()

Open std-any-emplace opened this issue 2 years ago • 0 comments

int main()
{
	auto token = std::stop_token{};
	auto thrd = std::jthread{[](std::stop_token){}, token};
	assert(thrd.get_stop_token() == token); // surprise

	return EXIT_SUCCESS;
}

Just small question regarding the intended way the jthread ctor is used, because that was shown to me today as an alternative and valid way to use a jthread. I think that should not be allowed or otherwise the explicitly supplied stop_token should be copied/moved into the jthread so that the assertion holds. Or else the result of get_stop_token() may "surprise" when used IMHO.

std-any-emplace avatar Jul 06 '22 15:07 std-any-emplace