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, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from sonic314-48.consmr.mail.sg3.yahoo.com (sonic314-48.consmr.mail.sg3.yahoo.com [106.10.240.172]) by gnuweeb.org (Postfix) with ESMTPS id CC25D80B3B for ; Mon, 29 Aug 2022 05:31:44 +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=bai4cqnq; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661751101; bh=lvd/0Pc8GASODSbhDcqaKRPDfBtBfWzY042TAJj7Lds=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=bai4cqnqhl2jSLLIv9T5rZpb6qrkVbBhQVvAo60VeYhEWQpqoCV1VXBp+ajh/x3LMoOTCGqH6tOhvJuwEJf7CmjRbvfi4iDcqXq99BGq+VXOCyhBymOwzIIQNiDIVc8liRAi+gB3dNy7aCztANZTwO2AREik2ntGxRbE4NhiUpWysNeAhXz/anmQ2HYhVdD15XiOIgtZRasdsXnEANPjH49Aqey+WOs0TsYBZpAgR3h3aneip8SOSTHPhFmi+YU7KiAxoCfoW5qnEpWYvNebOASqzUZd/HD0zXf0AY3MaYJ5yK0U8uYP169B2524t8FpM4LL4u+uVQr3sQskdo7kUQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661751101; bh=xWRVIoleySPTB5B6cZhMDf465P0SNCA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EtTKzBySMWW0jaMWUI1.5RGRxZB24pwPiW84m1WjnhHkWEgF_vyDl7MSVBf_e4k2jDhq6N 1EJNmRwfkUWChWriMvEbhitQCjksA4b8rgCmwGr1dS0AgmRzAOSVnNTnuIhC.D2WFYioVfiQv1Kt Eyjkcc8fjBjQTjILEHDGI2fmk81KL1nyG4oNKD7JtgwxKUtZY0biFX2a5aBgT3L9j09HNqRssb9m W2E6miOXC9iEIvLzAloa7AF7FZnzSmGCqo1CK9fzXGGQ21W6aEO7jgXzx1s8HCv3PnAHqSK4V_BG KXtuzuPE7uy2JrF_WZ6bVcgu6UthuaLcTrW4swNoRmv_rwLjcHoePakP.ddXmUmSFR8Ej7uk3znK WfrBVVeEWRV7cp7d1tx4SRZmcg2hePj3bUPEsWm5RujwXIVmBODfgSIAKJWtHDpqV7o245fiqyf3 5jS1MzxiMDmWMhWg489pYFQi_cAeM5xJqRgcB4vlrjtXrOEfHv7WVEgLe92O0Yvysf9bkjSIWcow fMci5FuVGKkikZIdrHKTpw1JmqCUdGXFeDjeMzd4vjUJL6gtmeCiv8qsdTp780LdiPK4ihrrm2R9 D0TH5Y50lvQ_SgJA- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.sg3.yahoo.com with HTTP; Mon, 29 Aug 2022 05:31:41 +0000 Received: by hermes--canary-production-sg3-6f58cd9b5-fnk8z (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8ebb680aa0a164b2f3c8acbcfb0ea268; Mon, 29 Aug 2022 05:29:38 +0000 (UTC) Message-ID: Date: Mon, 29 Aug 2022 12:29:36 +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: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. -- Ammar Faizi