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 F0B7D80B33 for ; Mon, 29 Aug 2022 05:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661750674; bh=99QSnmZI+LW8jD8e5B5s9KJ9XVD+Ggs7E5sM1EJfLiE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mqdsBiu5/Di+YOcoUmyacELCahTATfpFjwGIcLA7jrAesMhOAVQhPIrUSP7Edv9qb /8kuMj5gBfLgkQ5FIZsyxFz2+sB5pxnppVGpyd2KCCXeSyrn4Pc+UMiNOj+XzEpRTd NEtjjh2JhQmYKz0HoknZkc4EeAxfwqVOOhZDKC8fLZ7lgsiX2gmea6bY1OfG5uVCib qj55A0feLuwg1MlKKJ6YgQ9zcM0Eg74I9IEDHK0+zS33NrNwnn06nWqKXfROciAyoJ u1FZ4VQSmXbeX5O0MNYkzoTe24iVFLKclWM8cTHfu4IYcmF8NmbkUo/Xg89vc43Zu6 SSwA9V3uTTajQ== Received: by mail-lj1-f181.google.com with SMTP id s15so1797841ljp.5 for ; Sun, 28 Aug 2022 22:24:34 -0700 (PDT) X-Gm-Message-State: ACgBeo0BnCnxRPiI8w69RyGtwu7WkPQ+oHSoOnnYwUWiGmusFqwlL1mF PGlX202/v1xplHZqyMF4KLUtAMdt0QcTqi5T+7I= X-Google-Smtp-Source: AA6agR7DPgSr9tVfAEkMSHAU67VIyeBIVp4hdm6DPxKlsY9zGbpUcPuMcuhYrQL6stHMUvF4gUj3Y0tHkP0Du22IsNk= X-Received: by 2002:a2e:b8ce:0:b0:261:ada1:d803 with SMTP id s14-20020a2eb8ce000000b00261ada1d803mr4808124ljp.143.1661750673096; Sun, 28 Aug 2022 22:24:33 -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:24:21 +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: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? tq -- Viro