From patchwork Sat Oct 1 18:34:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: LIU Hao X-Patchwork-Id: 1629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp338204wrs; Sat, 1 Oct 2022 11:36:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6z9m6Wyzzh4RhEYmQIaqm82hruAkYmXWzLP07OXuWITgzZQ4RArMC8HpdEZz05f4X0ep7n X-Received: by 2002:a17:907:3205:b0:770:8554:c4ee with SMTP id xg5-20020a170907320500b007708554c4eemr10598247ejb.39.1664649375947; Sat, 01 Oct 2022 11:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664649375; cv=none; d=google.com; s=arc-20160816; b=Lh1R+sUM+HohamiTY+7Ea1U4ReIvkLfT5IZqGkuX7ur3dxNDNHftvjk+bzIg1Hla6B kDPB5zimYbr1LLoCmYKcvSzFwBkBYraJvwxgWAlwE/tJsIGpuzXYl+no0tpvkYcFM1Xj 5LwahlhIJLu5SkuXlO7sObGEw0xGkYpLojHAcgqJEYO2shoUZstaMzHyMcH4UdP+WSnO Whx3NIxK3PScneqewaMsoM8MXpN/HS18z2SxCKyRde4JTvj3xwPCs5GcizAjsf3ty5lw ui4PKIan0mMV7PHmc6PiUfPS58o6r5JpKWf279Kup4xcjSGYy9wL3x2rwuW6uk91c7kn fpag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=kRZpRSV+HU4+v9bti/+C9z6ELD5WgLRkxfzMriyC1Dc=; b=aGFmSUh9Q6+MFQav1Vaha/QNUAQ9SPG0kfi93PFVW1mRvTCpZOs5iZf92zABq5OEoF 0thhxpDO8QtEfPwtzg5cyuYh8OriCTFsiOZTO8/TdossjYGK30BSVxAv6yhh6QJpXJ4C 2MlPEDHyv18ox309PtR9KWM5JMnH/Z3OydEJowVLv6e++yzjnenbQhrc947LAW9KFyg0 N+kVkDdsWXCOKE5YRtxFsnfmldv9Id3rhViSYoEW0H5zQgFqAXrqQl230DmLyitzdhyq kkHALWMJx3H4KINxhrSboYcbmrjQD0/JQJBfa+d6L66DHhYjgbVSFo5KV93Bzx5G0BEl wzOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OcbiUYGv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gm1-20020a1709073d0100b0078034101c0esi5171805ejc.978.2022.10.01.11.36.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 11:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OcbiUYGv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30E113854163 for ; Sat, 1 Oct 2022 18:35:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30E113854163 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664649350; bh=kRZpRSV+HU4+v9bti/+C9z6ELD5WgLRkxfzMriyC1Dc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OcbiUYGvnSgK5k/lDV5YqWez88YjiBECfj+TRH7Vn5eG25+Wj9yvMgX4c4V0XykXK 3PbBWaId3OkgXENpx7u9FF8+HDNbtAdLm6X8d07H+3AAA8W4LujiE2f06MNHgFfWQI JOXN1KoLZT5xBsfS852gjorbmk00fjzaLXWX3RCc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from m15111.mail.126.com (m15111.mail.126.com [220.181.15.111]) by sourceware.org (Postfix) with ESMTP id 24DD83858D38; Sat, 1 Oct 2022 18:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24DD83858D38 Received: from [192.168.1.2] (unknown [101.93.199.8]) by smtp1 (Coremail) with SMTP id C8mowABnSm5FiDhjozY_Cg--.25468S2; Sun, 02 Oct 2022 02:34:46 +0800 (CST) Message-ID: <0f1f223a-3756-1da3-bd1d-b87edd34e1f9@126.com> Date: Sun, 2 Oct 2022 02:34:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Adding a new thread model to GCC X-CM-TRANSID: C8mowABnSm5FiDhjozY_Cg--.25468S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF1UCw18uFWUAFWruFWkXrb_yoW8Gw4rpr W5Wrn0grWvyry7u3WkJan3Xr48Ja18ZF9rWa4rJryvva1rWF48WFy8KFZ0va45Ar95Gw17 AF45Zrn5Aa1qvFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jJ6pPUUUUU= X-Originating-IP: [101.93.199.8] X-CM-SenderInfo: 5okbz0xxvhqiyswou0bp/1tbiFweNRlpEE+qNkQAAsg X-Spam-Status: No, score=-3132.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_VALIDITY_RPBL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_SBL_A autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: LIU Hao via Gcc-patches From: LIU Hao Reply-To: LIU Hao Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745511384143160039?= X-GMAIL-MSGID: =?utf-8?q?1745511384143160039?= Greetings. After some years I think it's time to put on this topic again. This patch series is an attempt to add a new thread model basing on the mcfgthread library (https://github.com/lhmouse/mcfgthread), which provides efficient implementations of mutexes, condition variables, once flags, etc. for native Windows. The first patch is necessary because somewhere in libgfortran, `pthread_t` is referenced. If the thread model is not `posix`, it fails to compile. The second patch implements `std::thread::hardware_concurrency()` for non-posix thread models. This would also work for the win32 thread model if `std::thread` would be supported in the future. The third patch adds the `mcf` thread model for GCC and its libraries. A new builtin macro `__USING_MCFGTHREAD__` is added to indicate whether this new thread model is in effect. This grants `std::mutex` and `std::once_flag` trivial destructors; `std::condition_variable` is a bit unfortunate because its destructor is non-trivial, but in reality no cleanup is performed. I have been bootstrapping GCC with the MCF thread model for more than five years. At the moment, C, C++ and Fortran are supported. Ada is untested because I don't know how to bootstrap it. Objective-C is not supported, because threading APIs for libobjc have not been implemented. Please review. If there are any changes that I have to make, let me know. --- Best regards, LIU Hao From c522fa74c791ee8904b5906c6e18908b56071db5 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 27 May 2022 23:12:48 +0800 Subject: [PATCH 1/3] libgfortran: Use `__gthread_t` instead of `pthread_t` It used to cause errors if a thread model other than `posix` was selected, which looks like a leftover from a79878585a1c5e32bafbc6d1e73f91fd6e4293bf. libgfortran/ChangeLog: * io/async.h (struct async_unit): Use `__gthread_t` instead of `pthread_t`. --- libgfortran/io/async.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgfortran/io/async.h b/libgfortran/io/async.h index efd542a45e82..d57722a95e44 100644 --- a/libgfortran/io/async.h +++ b/libgfortran/io/async.h @@ -351,7 +351,7 @@ typedef struct async_unit struct adv_cond work; struct adv_cond emptysignal; struct st_parameter_dt *pdt; - pthread_t thread; + __gthread_t thread; struct transfer_queue *head; struct transfer_queue *tail;