From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (vps-42846194.vps.ovh.net [IPv6:2001:41d0:801:2000::2400]) by sourceware.org (Postfix) with ESMTPS id F0DA73857C6A for ; Wed, 17 Nov 2021 20:38:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F0DA73857C6A Received: from ubuntu.lan (unknown [IPv6:2a02:390:9086::635]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id F15EE823BB; Wed, 17 Nov 2021 20:37:59 +0000 (UTC) Date: Wed, 17 Nov 2021 20:37:55 +0000 From: Lancelot SIX To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 11/32] Return vector of results from parallel_for_each Message-ID: <20211117203755.glfe5dglqcfzbgn6@ubuntu.lan> References: <20211104180907.2360627-1-tom@tromey.com> <20211104180907.2360627-12-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211104180907.2360627-12-tom@tromey.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Wed, 17 Nov 2021 20:38:00 +0000 (UTC) X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Nov 2021 20:38:04 -0000 > + > +/* See the generic template. */ > +template<> > +struct par_for_accumulator > +{ > +public: > + > + explicit par_for_accumulator (size_t n_threads) > + : m_futures (n_threads) > + { > + } > + > + /* This specialization does not compute results. */ > + typedef void result_type; > + > + void post (size_t i, std::function task) > + { > + m_futures[i] > + = gdb::thread_pool::g_thread_pool->post_task (std::move (task)); > + } > + > + result_type finish (std::function task) > + { > + task (); > + > + for (auto &future : m_futures) > + future.wait (); Hi, There is a point here I missed when I read though the V1 of the series. I think you also want to use 'get' here instead of 'wait' (as you do in the non specialized version of the template). Wait 'just' makes sure the result becomes accessible (in this case, makes sure the task is executed), while get also accesses it. Even if the task returns nothing, if an exception is thrown during execution of the task, calling wait will just make sure the exception is stored in the future object. Calling get will re-throw the exception, which is probably what we want. Best, Lancelot. > + } > + > +private: > + > + std::vector> m_futures; > +}; > + > +} > +