From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sonic313-48.consmr.mail.sg3.yahoo.com (sonic313-48.consmr.mail.sg3.yahoo.com [106.10.240.107]) by gnuweeb.org (Postfix) with ESMTPS id 67FD980B1F for ; Mon, 29 Aug 2022 05:50:38 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=b/lTGc3w; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661752235; bh=fedB+brtbqgEvrGrDuriSIQhsfaeq/8n/EJeoLtTEas=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=b/lTGc3whzAXw5NnAh8WkhsOZiXIlh6gQUT7wRsdds++XQwhYkHdyq3UggaILnQsd6i9bJ/IEiuIO1ti31bsZFYiBMllPT1Gx3yXdYLkiwlhHHWjJ7cOk/mMpQy6ZB/rk/RvGXyPadU8OGeCUS5yM1q+ooU5pl7j+FIK5VcqokxH2u+sNQPPbYhdUE7IxIahw82/v4ISkS6S/tyUYankHDVjyNoJ82oTIMiIKqelnuRVLIZc7p6rIxhVBtI5FPzYHDoSVqSKC0bfsJeUQ25w5m6xKQmF4kiNhb0TSoJlM0q+6Q2+s+A9lYNWjBlho6nMA7PuksIocER5jVSwDxrjEw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661752235; bh=qdEaSt4xMbItkoUlG1ClmQyOAz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1Tu1j dvhOG6Kq_zNfmFxuxJ9RibaRrkMW95BUE9Dn3UjStYNlWowFoscl.eiZrsioBCcfSKD_I5z882Mj zJYpdZFmzEQCuVXos9VdmluwUtsYoQcnWo7oCUrWE6wODJw752R8gk.n.8a9zd4Oze6387VqSE5G 34kSa1nAmx8A6qMn7Dhw9jCl1lfDYy.8x74gdb8hhCFebHuVT5475thyOkFVg_5o4W.A4YmLyLrM VV6jV1rV_yAYCHzu2Bt.GTBoHKR.CcEX6QDH7MxsmYTHzbYGH9gaJOdVPy_QS34TqHrFqch4FyDt IDhcI70QhlWT6xipErPAtOei36wRAAk.siOl5FBIBnOzgXasgBfFnCUVW1z5B_uKAAqfQKpGdx8X 8qs518OTPX3X4nLR7SCPDgqtltl9mRQWMYoWFq7Lca76g46rkn1Ae_pjHUPJwinhi53M1pWhAY1B 7YkqY.xT9SZF79uGSvWdxmTul3NVNpHl_sBh14.RH49b76OShtie.vT3n.e5uKyLkTbF5FIBpjcv sZpN0Xj6Ct_wI7DlFsn9VO0KPZZ5rj_ODsc1TVenQXcXD9DyiDFcGfBHSzysJ80xK9CfHH2AjGB6 Kv.A.AI8aso3l3qY- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.sg3.yahoo.com with HTTP; Mon, 29 Aug 2022 05:50:35 +0000 Received: by hermes--canary-production-sg3-6f58cd9b5-fnk8z (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 5a8610e8a585f76fbbddb2d56d486e01; Mon, 29 Aug 2022 05:48:33 +0000 (UTC) Message-ID: Date: Mon, 29 Aug 2022 12:48:31 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [RFC PATCH v1 2/2] chnet: Implement `get_thread()` and `put_thread()` function Content-Language: en-US To: Alviro Iskandar Setiawan Cc: Ammar Faizi , Muhammad Rizki , Kanna Scarlet , GNU/Weeb Mailing List References: <20220829011127.3150320-1-ammarfaizi2@gnuweeb.org> <20220829011127.3150320-3-ammarfaizi2@gnuweeb.org> From: Ammar Nofan Faizi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.20595 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo List-Id: On 8/29/22 12:38 PM, Alviro Iskandar Setiawan wrote: > On Mon, Aug 29, 2022 at 12:29 PM Ammar Nofan Faizi wrote: >> On 8/29/22 12:24 PM, Alviro Iskandar Setiawan wrote: >>> On Mon, Aug 29, 2022 at 12:17 PM Alviro Iskandar Setiawan wrote: >>>> On Mon, Aug 29, 2022 at 11:54 AM Ammar Nofan Faizi wrote: >>>>> On 8/29/22 11:41 AM, Alviro Iskandar Setiawan wrote: >>>>>> On Mon, Aug 29, 2022 at 8:11 AM Ammar Faizi wrote: >>>>>>> +static base::Thread *get_thread(void) >>>>>>> +{ >>>>>>> + const uint32_t max_ch_thpool = g_max_ch_thpool; >>>>>>> + const uint32_t nr_ref_split = 2048; >>>>>>> + struct ch_thpool **thp; >>>>>>> + struct ch_thpool *ret = nullptr; >>>>>>> + struct ch_thpool *tmp; >>>>>>> + uint32_t min_ref_idx; >>>>>>> + uint32_t min_ref; >>>>>>> + uint32_t i; >>>>>>> + >>>>>>> + g_thpool_lock_.lock(); >>>>>>> + thp = g_thpool; >>>>>>> + if (!thp) { >>>>>>> + g_thpool_lock_.unlock(); >>>>>>> + return nullptr; >>>>>>> + } >>>>>> >>>>>> in what situation @thp can be nullptr? >>>>> >>>>> When the chnet_global_destroy() is called. >>> >>> btw, i missed a case on the chnet construction, you do >>> >>> thread_(*get_thread()), >>> >>> if get_thread() returns a nullptr, the @thread_ will become a >>> reference to a nullptr, it will definitely break, how do you handle >>> this? >> >> I don't think we need to handle that. If @thp ever be a nullptr in a >> get_thread() call, then it's a misuse of the API. We must never call >> get_thread() after chnet_global_destroy() is called. It doesn't make >> much sense to have this situation. > > if this should never happen, then why do you do a null check there? > your null check doesn't make much sense too! why are we returning > nullptr if we exactly know that the caller will randomly fault if that > happens, i can't accept your reasoning OK. Fine, let's omit that nullptr return. To assert that path, we perform a CHECK() assertion, so it will just crash the whole program with a full call traces if the contract is violated. This way also makes debugging process easier. Are you happy with this change? Incremental is: diff --git a/chnet/chnet.cc b/chnet/chnet.cc index 782e4fe..fc536d2 100644 --- a/chnet/chnet.cc +++ b/chnet/chnet.cc @@ -647,10 +647,7 @@ static base::Thread *get_thread(void) g_thpool_lock_.lock(); thp = g_thpool; - if (!thp) { - g_thpool_lock_.unlock(); - return nullptr; - } + CHECK(thp); tmp = thp[0]; if (!tmp) { -- Ammar Faizi