From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id E0E0C387088C for ; Thu, 19 Nov 2020 13:36:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E0E0C387088C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-vRyi00DXMUmo9erdv9kDRA-1; Thu, 19 Nov 2020 08:36:51 -0500 X-MC-Unique: vRyi00DXMUmo9erdv9kDRA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FD811015C80; Thu, 19 Nov 2020 13:36:49 +0000 (UTC) Received: from localhost (unknown [10.33.36.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8C9360636; Thu, 19 Nov 2020 13:36:48 +0000 (UTC) Date: Thu, 19 Nov 2020 13:36:47 +0000 From: Jonathan Wakely To: Thomas Rodgers Cc: libstdc++ , gcc-patches List , tom@tromey.com Subject: Re: [PATCH] libstdc++: Enable without gthreads Message-ID: <20201119133647.GE1312820@redhat.com> References: <20201111161340.GA115319@redhat.com> <20201111173107.GX503596@redhat.com> <20201112170745.GC503596@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2020 13:36:55 -0000 On 16/11/20 14:43 -0800, Thomas Rodgers wrote: >This patch looks good to me. Committed now. >It would be great to find a way to do a similar refactoring of condition_variable. Yes, probably once stage 1 opens for GCC 12. >> On Nov 12, 2020, at 9:07 AM, Jonathan Wakely via Libstdc++ wrote: >> >> On 11/11/20 17:31 +0000, Jonathan Wakely wrote: >>> On 11/11/20 16:13 +0000, Jonathan Wakely wrote: >>>> This makes it possible to use std::thread in single-threaded builds. >>>> All member functions are available, but attempting to create a new >>>> thread will throw an exception. >>>> >>>> The main benefit for most targets is that other headers such as >>>> do not need to include the whole of just to be able to create a >>>> std::thread. That avoids including and std::jthread where >>>> not required. >>> >>> I forgot to mention that this patch also reduces the size of the >>> header, by only including instead of the >>> whole of . That could be done separately from the rest of the >>> changes here. >>> >>> It would be possible to split std::thread and this_thread::get_id() >>> into a new header without also making them work without gthreads. >>> >>> That would still reduce the size of the header, because it >>> wouldn't need the whole of . But it wouldn't get rid of >>> preprocessor checks for _GLIBCXX_HAS_GTHREADS in . >>> >>> Allowing std::this_thread::get_id() and std::this_thread::yield() to >>> work without threads seems worth doing (we already make >>> std::this_thread::sleep_until and std::this_thread::sleep_for work >>> without threads). >> >> Here's a slightly more conservative version of the patch. This moves >> std::thread and this_thread::get_id() and this_thread::yield() to a >> new header, and makes *most* of std::thread defined without gthreads >> (because we need the nested thread::id type to be returned from >> this_thread::get_id()). But it doesn't declare the std::thread >> constructor that creates new threads. >> >> That means std::thread is present, but you can't even try to create >> new threads. This means we don't need to export the std::thread >> symbols from libstdc++.so for a target where they are unusable and >> just throw an exception. >> >> This still has the main benefits of making include a lot less >> code, and removing some #if conditions in . >> >> One other change from the previous patch worth mentioning is that I've >> made include so that >> std::reference_wrapper (and std::ref and std::cref) are defined by >> . That isn't required, but it is a tiny header and being able >> to use std::ref to pass lvalues to new threads without including >> all of seems like a kindness to users. >> >> Both this and the previous patch require some GDB changes, because GDB >> currently assumes that if std::thread is declared in that it >> is usable and multiple threads are supported. That's no longer true, >> because we would declare a useless std::thread after this patch. Tom >> Tromey has patches to make GDB handle this though. >> >> Tested powerpc64le-linux, --enable-threads and --disable-threads. >> >> Thoughts? >> >> >> >