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=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by gnuweeb.org (Postfix) with ESMTPSA id A1DA88061E for ; Mon, 29 Aug 2022 05:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661751508; bh=p4eJRXBGHn8Ybjqudurz4RK13bEC7JSbu1V59t0H5so=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Qg1Ds0jVvs9fHrkUGY6FT3HaBnbADuLIMPGiUzHZpMi+/0vJJYIg4VXFxtuzLn0iG 5orUrA/XeOGlDrpmrtCE4rutWjo3BrgQ4oNN0AZnsubZjk2tQzfxU74f4sE4CLavKa njJIBtwzojAYWv4JX6iDVnN/tnahHjWzPQ25QKGiamJW9zFbL2+E1f/CmLX9OdkQMk PkXLGujJ4RQsGAqvKE8kFQFDGl7owTMyf0jBW5lcwFtV0qLM2DZz+dHXFJy9/hWbpQ SAKZEs5+d4gbWoB7OirNGusv/Tc1JrxpU0JAlXh4A0k1jq6vpYt+5v94m5iYxYgxOY i0S4KX4ownH5Q== Received: by mail-lj1-f181.google.com with SMTP id w19so3997507ljj.7 for ; Sun, 28 Aug 2022 22:38:28 -0700 (PDT) X-Gm-Message-State: ACgBeo3nQXuu1Cp5RXSwDssDOHixcIkteZnUcsNtezHwtU1/1/fZm4Ag Woahu8OKhM9zg0kFM177uR7sBiaKDh4aN3Hpybc= X-Google-Smtp-Source: AA6agR70b6tIwYOoZDA6PkPtWiIiS80J0/oQvGMo9aJ4n1PxCCTgnaH3JAc+zzq88oORhp+Uphgdd6xMAWFHp5gy71U= X-Received: by 2002:a05:651c:2381:b0:261:e736:5121 with SMTP id bk1-20020a05651c238100b00261e7365121mr4674110ljb.174.1661751506787; Sun, 28 Aug 2022 22:38:26 -0700 (PDT) MIME-Version: 1.0 References: <20220829011127.3150320-1-ammarfaizi2@gnuweeb.org> <20220829011127.3150320-3-ammarfaizi2@gnuweeb.org> In-Reply-To: From: Alviro Iskandar Setiawan Date: Mon, 29 Aug 2022 12:38:15 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v1 2/2] chnet: Implement `get_thread()` and `put_thread()` function To: Ammar Nofan Faizi Cc: Ammar Faizi , Muhammad Rizki , Kanna Scarlet , "GNU/Weeb Mailing List" Content-Type: text/plain; charset="UTF-8" List-Id: 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 -- Viro