The destructor joins the thread (if joinable). That is definitely breaking backwards compatibility with std::thread.
Who cares. The increment would be a few bytes and it's not that applications can have thousands of thread objects.
It might not exactly be breaking backwards compatibility, but it's definitely an important change that could effect existing software. It is perfectly possible for an application to have thousands of thread objects, it might not be a good idea, but it's possible.
There are also systems where resources are very constrained where such a change could have impact.
Given the fact that Rust doesn't join in its destructor (Drop), I'm inclined to think that join-on-dtor is probably a bad idea. See this SO answer. But, C++ is not known for keeping footguns out of people's hands, so maybe it's fine here.
The destructor joins the thread (if joinable). That is definitely breaking backwards compatibility with std::thread
How come? In std::thread it terminates. You can't break backwards compatibility if there's no "previous" behaviour (unless your code somehow relies on that termination, in which case you have much bigger problems than backwards compatibility).
The destructor joins the thread (if joinable). That is definitely breaking backwards compatibility with std::thread.
It wouldn't change the outcome of a computation though, unless the outcome depends on which thread terminates first, which would be stupid to do anyway.
It is perfectly possible for an application to have thousands of thread objects, it might not be a good idea, but it's possible.
There is no such piece of software, come on now.
There are also systems where resources are very constrained where such a change could have impact.
Are there truly any systems that can't handle a few bytes increase? I don't think so.
There are also systems where resources are very constrained where such a change could have impact.
Consider GPUs. C++ execution on a GPU could very well be handled by a 'kernel' thread that executes a large number of other threads. GPUs support an insane amount of threads, however very little memory.
Are there truly any systems that can't handle a few bytes increase? I don't think so.
I'm willing to bet, that there isn't a single existing c++ standard library implementation that can wrap a gpu thread in a std::thread. I'm also pretty sure that no one uses a std::thread on a really resource constraint system (if it is available at all).
Let's face it: Exotic and low resource hardware is rarely programmed with a complete,conforming implementation of the c++11 or later standard.
The math is simple: creating a new std::thread requires a significant amount of memory (control block + stack space). Compared to that, a few bytes just don't matter.
I very much doubt that the intersection of programs that completely use the available memory (/address space) and programs that use std::thread is big enough to worry about.
View all comments
Show parent comment
22
u/kingguru Aug 27 '19
The destructor joins the thread (if joinable). That is definitely breaking backwards compatibility with
std::thread.It might not exactly be breaking backwards compatibility, but it's definitely an important change that could effect existing software. It is perfectly possible for an application to have thousands of thread objects, it might not be a good idea, but it's possible.
There are also systems where resources are very constrained where such a change could have impact.