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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id ECED738582AB for ; Wed, 22 Mar 2023 14:31:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECED738582AB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679495494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1vuUoCJsPNIIscjdK+VWEPCqZLk7AkMzzGZXAJrqAiM=; b=O2qfH/Y2bGm0gjTsoC7TBJRjoeMsqJChlgzBmxs8NoWpwqsOQ8mpPWYWKH4mBFPbjOlkw4 nkSNwV+SB2DAhdzsIZaKROFpvok+9ogrRyttUwHIZwAfaAaUlN68ok1TE0OuS1F88balCM HbPK0EM4WJ2W/AjizpV5Ql/VVidZBdU= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-HUXANY-7M2GngeP2wKa9ZQ-1; Wed, 22 Mar 2023 10:31:33 -0400 X-MC-Unique: HUXANY-7M2GngeP2wKa9ZQ-1 Received: by mail-lj1-f197.google.com with SMTP id t17-20020a05651c205100b0029f839410fcso1335067ljo.1 for ; Wed, 22 Mar 2023 07:31:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679495491; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4VkV64v3mIQftvrK+xwehDqztebySmYjGDYsmHTy//Q=; b=vIHTyRRnOGhNlplpQcGWCKtU3IY9kaHFVg+l5KcFtCa4ezVqXWmvGs+9/+EzA9uZwb 7SqoGJR3s5/PEqERFWcJ95wYtyloTc9fpmd6C9xTVN5jbvdw96CiUt6FY9yduJ5sy9P0 HMNyOz6xltxCa1ZCCIA3rE8+hXSQ1p3milIW+zmfccmJn6j0WIXD9JqhI2TKE0PhW7Bv 6L68ZI3XIkoAebj6TZ31ETXADR4bvqHrNclGD209OBsabm10Chcqoe0i4zVzCzqw6gKY PsbGppe455jviuLjZB2xFWRVE90w78izspYhCF2jsuJiVvQsdJFauXcaeOuRn2ZPu48t tQlQ== X-Gm-Message-State: AO0yUKW5oDBHDEH5KJ8LxqGZfVJ0Z7PYc23KOpSr03wY+2Ig1LLloH8l awKhQ+DOVnsa8l8qRTOwrSdFUNoCJX8qAWObUCZrMMVP63XlMysqD9qz1G+4Qy+3diFSBDWeAt1 Q+mF7P2Q2Gv9CEmNVCGgP5TT+u4Q7vD8= X-Received: by 2002:ac2:555a:0:b0:4e9:d5e5:3fe8 with SMTP id l26-20020ac2555a000000b004e9d5e53fe8mr2032003lfk.8.1679495491648; Wed, 22 Mar 2023 07:31:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YUV5Tj3/VOcOq4oRSlIn24Yt33vlrX6dQUVT05XgTWwhhDGeBDRmlscrZ1LTWWqQOdV8Su4ulxdTvYwE6ChIM= X-Received: by 2002:ac2:555a:0:b0:4e9:d5e5:3fe8 with SMTP id l26-20020ac2555a000000b004e9d5e53fe8mr2031996lfk.8.1679495491357; Wed, 22 Mar 2023 07:31:31 -0700 (PDT) MIME-Version: 1.0 References: <20210323163937.GA3008@redhat.com> In-Reply-To: <20210323163937.GA3008@redhat.com> From: Jonathan Wakely Date: Wed, 22 Mar 2023 14:31:20 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Implementation of class strand To: "Alessio G. B." Cc: libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000002a1e2d05f77e045b" X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000002a1e2d05f77e045b Content-Type: text/plain; charset="UTF-8" On Tue, 23 Mar 2021 at 16:39, Jonathan Wakely wrote: > On 12/03/21 13:21 +0100, Alessio G. B. via Libstdc++ wrote: > >I expanded the implementation of the class strand of the Networking > >TS. Essentially, I > >implemented a token system so each thread knows when it can execute; > >the system is organized > >with 2 integers moving as a clock. > > Thanks for this patch. I'm not sure when I'll have time to review it, > and it might not be in time for the upcoming GCC 11 release. But the > patch has been received and will get reviewed, thanks. > Well I didn't think it would take me two years, sorry about that :-( + template + void + invoke(unsigned int token, _Func&& __f) + { + std::unique_lock __lock(_M_mutex); + + _M_cv.wait(__lock, + [token, next_token = _M_next_token]() + { return token == next_token; }); + + try { decay_t<_Func>{std::forward<_Func>(__f)}(); } + catch(...) { } + + _M_next_token++; + + __lock.unlock(); + + _M_cv.notify_all(); + } It looks like this will run a user-provided function while holding the mutex lock. Won't that deadlock if the task added to the strand adds another task to the same strand? Is that forbidden by some requirement in the TS that I've forgotten? --0000000000002a1e2d05f77e045b--