From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 309A63894C34 for ; Thu, 15 Dec 2022 19:08:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 309A63894C34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd31.google.com with SMTP id y4so146808iof.0 for ; Thu, 15 Dec 2022 11:08:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6c11BM7H2ehlIQ2h6uhka6qrIBJ25uDWDrIUxdk+05o=; b=RZI2lop3xp1Pf6SVfYYei1LUa2VBwMt3iiNXAWCq0KlsD0xGoX0ZUHukACFp1HZs59 J5GeS7JW7euxflQM8tvh0dSI0mvvYhAqAfJFrO+qcJVN7OMDdov9+izJU5Rs5NADHz9w kDHAIJAYdFogyEaf7hsAoEGjhMQpepJNNTId77MKWppOyig1bxapPrpLfGWw7tLuMXoF qGlcGsHQfvbMiJjbTF49gYL99jrCG02+1iTih/otj5qmPdDlpYRgF9RRbbZH6IjGWIZc CvkBCX63U4VuW889VeEHqVtTUKKqEeTBy9daH5kLB7SlWuGXIejKdPsxOX6tt2UuKh55 aOsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6c11BM7H2ehlIQ2h6uhka6qrIBJ25uDWDrIUxdk+05o=; b=GGtkCoCAPTOd8yIcZSqSWjvXCakdNlmHTB6iqNnRRM8e43Yu8cTjD8W3ARq7futEWC jKqVxAEMGbDNEZH2qv8xgfqcg2EGZqdFFgG2KvHoLPhRraNndvqzQZ69OwUZXPED5YQA yr3PiiZXOs3Tx/cxeozNE4ZXqRL7ugbKrU/cSlHq4L8otW0cevifTKqPHS7rT2hcJ6o/ tJ7h6PjeV3HZUL+S4pCT1BGIeT21vUMvgN0iNq9aX+WjnpZjqpkgxfpiOxfTHio8U8Ea QsNHsHrC3w77IWDOmISq8+sZnteaM0P4CnKBCzFa0T63jM0aGftEqqThzgmw96GTfoHf Ypuw== X-Gm-Message-State: ANoB5pmkhuAtRF4qsSJ3wBqTOfADW9yenPlKhaLcFoT/h1TbTqH1FWTu fwT7+/oNDyNvTFZ0jLbmS9nxkEXtBNY5awSM X-Google-Smtp-Source: AA0mqf7WAvJcn4OVI7qoBBz4CykWtrd8l2maaEqO+cj6npt1Z++EZL80x9BdZ50gFW/WqA7202ub8Q== X-Received: by 2002:a6b:4e0e:0:b0:6ca:d145:9e with SMTP id c14-20020a6b4e0e000000b006cad145009emr16608235iob.14.1671131290408; Thu, 15 Dec 2022 11:08:10 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id y74-20020a6bc84d000000b006e0338b60a5sm1413962iof.22.2022.12.15.11.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 11:08:09 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/4] Avoid submitting empty tasks in parallel_for_each Date: Thu, 15 Dec 2022 12:07:56 -0700 Message-Id: <20221215190759.2494095-2-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221215190759.2494095-1-tromey@adacore.com> References: <20221215190759.2494095-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: I found that parallel_for_each would submit empty tasks to the thread pool. For example, this can happen if the number of tasks is smaller than the number of available threads. In the DWARF reader, this resulted in the cooked index containing empty sub-indices. This patch arranges to instead shrink the result vector and process the trailing entries in the calling thread. --- gdbsupport/parallel-for.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index acd9137efbd..ed460f31f63 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -70,6 +70,12 @@ struct par_for_accumulator return result; } + /* Resize the results to N. */ + void resize (size_t n) + { + m_futures.resize (n); + } + private: /* A vector of futures coming from the tasks run in the @@ -108,6 +114,12 @@ struct par_for_accumulator } } + /* Resize the results to N. */ + void resize (size_t n) + { + m_futures.resize (n); + } + private: std::vector> m_futures; @@ -232,6 +244,17 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last, end = j; remaining_size -= chunk_size; } + + if (end == last) + { + /* We're about to dispatch the last batch of elements, which + we normally process in the main thread. So just truncate + the result list here. */ + count = i; + results.resize (count); + break; + } + if (parallel_for_each_debug) { debug_printf (_("Parallel for: elements on worker thread %i\t: %zu"), -- 2.34.3