Skip to content

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

@std-any-emplace

Description

@std-any-emplace
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions