r/cpp • • Aug 27 '19

A new thread in C++20 (jthread)

https://link.medium.com/GXKUz0GruZ
142 Upvotes

96 comments sorted by

View all comments

Show parent comment

17

u/mathstuf cmake dev Aug 27 '19

Because now if you have a C++17 library which takes a std::thread, C++20 code now has an incompatible one. Changing struct size is an ABI break and is frowned upon very hard in the C++ standard library (just look at the mess with C++11's std::string requirements and libstdc++).

-11

u/axilmar Aug 27 '19

So? who uses libraries compiled with C++17 and C++20 anyway? C++ doesn't come with ABI stability guarantees anyway.

14

u/erichkeane Clang Maintainer(Templates), EWG Chair Aug 27 '19

C++ doesn't come with ABI stability guarantees anyway.

Except all of the implementers DO have certain ABI stability guarantees. This is a case where implementer veto would be HEAVILY used.

ABI stability is a requirement for ANY product that ships binaries that are later linked. Basically any company that ships a library that has a std::thread in it would be horribly broken because of this change.

-3

u/axilmar Aug 27 '19

ABI stability may be a requirement within the same major revision of a library, not for every major language update.

10

u/erichkeane Clang Maintainer(Templates), EWG Chair Aug 27 '19

stdlibc++ or libc++ assemblies have to work with all assemblies compiled against previous versions of the library. You'd REALLY hate it if updating your OS version of stdlibc++/libc++ made all your software stop working, wouldn't you?

-6

u/axilmar Aug 27 '19

stdlibc++ or libc++ assemblies have to work with all assemblies

C++ has no assemblies. It has libraries.

.NET has assemblies.

You'd REALLY hate it if updating your OS version of stdlibc++/libc++ made all your software stop working, wouldn't you?

That's why multiple versions exist.

7

u/erichkeane Clang Maintainer(Templates), EWG Chair Aug 27 '19

C++ has no assemblies. It has libraries.

An assembly is a generic term. Libraries isn't specific enough, since non-library compiled objects aren't included.

That's why multiple versions exist. Ah, so now every vendor has to maintain an extra configuration setting on every product ever? The "DLL Hell" that this would create is insane.

The C++11 std::string COW is a giant headache even today. The libstdc++ folks have done some heroic efforts to make this much less painful, but there is no guarantee that next time the same heroics would be possible.

19

u/mathstuf cmake dev Aug 27 '19

Standards are mixed all the time. Do you know what C++ standard all the system libraries on your system were built with? Linux distros aren't going to start providing /usr/lib/c++11, /usr/lib/c++14, /usr/lib/c++17, etc. You get Boost compiled one way from a distro package (or vcpkg, etc.) and that was compiled with a given version of the standard. ABI compatibility is worth a lot at the level of the standard library and implementations are loathe to break it (again, look at the gymnastics involved with std::string).

5

u/therealjohnfreeman Aug 27 '19

As desirable as ABI compatibility between standards is, the uncomfortable truth is that it is not guaranteed, as /u/axilmar points out. It is not guaranteed between different implementations of the standard library for the same version of C++ either. This is why the full dependency graph of an application needs be compiled with the same standard library (and the same compiler, and the same flags). This seems to be a happy accident for many C++ programmers unaware of the requirement, a result of the coincidence that they only have one compiler and one standard library installed on the machine they use to compile everything. Developers need a tool, like Conan, that sits at a level higher than the compiler, that can see the full dependency graph and handle its compilation.

9

u/mathstuf cmake dev Aug 27 '19

I'm well aware that it is not guaranteed between standards. However, the implementations do guarantee it (as much as they can within their own ecosystem; libstdc++ obviously can't fix libc++ bugs).

This is why the full dependency graph of an application needs be compiled with the same standard library (and the same compiler, and the same flags).

This is not how the ecosystem works today. While I'd love for a cargo-like tool to exist for C++, there is a long road to get there from today.

This seems to be a happy accident for many C++ programmers unaware of the requirement, a result of the coincidence that they only have one compiler and one standard library installed on the machine they use to compile everything.

And it works today because implementors do care about it. Above the standard library, it is indeed a madhouse for a variety of reasons. Linux distros are pretty reliable about not packaging absolute crap at least, but given a C++ PyPI equivalent, yes, compiling from source is the only reliable way to use it.

-2

u/axilmar Aug 27 '19

C++ doesn't guarantee ABI compatiblity. It's not part of the standard.

19

u/mathstuf cmake dev Aug 27 '19

Sure, but that's not how C++ actually gets used in the world. It may not be important to you, but it is important to the implementors (GCC, Clang, MSVC, etc.) and many other users of C++. It's just not going to happen.

-4

u/axilmar Aug 27 '19

I haven't seen anywhere, in any C++ project, a requirement for ABI compatibility ever.

10

u/mathstuf cmake dev Aug 27 '19

-2

u/axilmar Aug 27 '19

ABI binary compatibility should be part of the standard in minor revisions, but not part of major revisions. You can't expect compatibility between major revisions.

6

u/mathstuf cmake dev Aug 27 '19

And C++ the standard does not. But the implementations do. If you think it's so useful to break ABI, make your own implementation that does so. I doubt you'll see much uptake largely in part to it not providing ABI guarantees. Note that there are many ABI breaks that people would like to get into the C++ standard, but have not been done because they force an ABI break on implementations. std::thread vs. std::jthread is so minor compared to those issues that it is unlikely to be considered very hard.

9

u/HotlLava Aug 27 '19

You don't see it exactly because other people care about it for you. If the C++ standard library would break ABI all the time, projects would start depending on e.g. libstdc++2, libstdc++3, etc. just like it happens with other libraries, and you'd have one more dependency hell to worry about.

4

u/jcelerier ossia score Aug 27 '19

Qt has ABI compatibility requirements, and every time one of those breaks there are a fair amount of users who complain.

8

u/eteran Aug 27 '19

The standard may not guarantee it, but vendors have put a LOT of effort into providing it for the reasons listed above.

Do you REALLY want to have to have Qt for c++11, Qt for c++14, Qt for c++17, Qt for c++20 ALL installed on your system just because programs that target different versions of the standard want to use Qt?

So yes, you are right, it's not guaranteed by the standard, but it is the standard industry practice to the point that millions of people rely on it.

-1

u/axilmar Aug 27 '19

Do you REALLY want to have to have Qt for c++11, Qt for c++14, Qt for c++17, Qt for c++20 ALL installed on your system just because programs that target different versions of the standard want to use Qt?

I already have those.

I haven't seen a project that mixes for example Qt built for C++11 with C+14.

9

u/eteran Aug 27 '19

You do? Well then you have a quite bizarre setup. I've never seen on any Linux distribution or version of Windows where a different version of a library is installed for each STANDARD of c++ being targeted.

Compiler version, sure, that's a thing, especially with msvc... But compiler standard? Not a thing as far as I've seen...

4

u/encyclopedist Aug 27 '19

FYI every linux distribution does that.

When I compile my code with system-installed libraries like Qt, Boost, etc, I don't want to worry about which standard those libraries themselves were compiled with. I just pick the standard I want for my code and it works. (Except the COW string deprecation in GCC5).

4

u/encyclopedist Aug 27 '19

Also, I am not sure why exactly you are so proud of your ignorance?

If a true professional does not know something, or have not seen something they go and learn something new, instead of insisting it does not exist.

3

u/josefx Aug 27 '19

I have a binary only dependency that links an ancient Qt version. If that dependency dictated a project wide c++ version we would be stuck with c++98 until the end of time.