From owner-freebsd-arch@freebsd.org Wed May 2 16:24:24 2018 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 843D4FAE274 for ; Wed, 2 May 2018 16:24:24 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C5E4D823AE; Wed, 2 May 2018 16:24:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id w42GOCPb078866 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 2 May 2018 19:24:16 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w42GOCPb078866 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w42GOCIm078865; Wed, 2 May 2018 19:24:12 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 2 May 2018 19:24:12 +0300 From: Konstantin Belousov To: Mark Johnston Cc: Ian Lepore , freebsd-arch@FreeBSD.org Subject: Re: callout_stop() return value Message-ID: <20180502162412.GA6887@kib.kiev.ua> References: <20180502152024.GA24397@raichu> <1525275297.57768.202.camel@freebsd.org> <20180502154237.GB24397@raichu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180502154237.GB24397@raichu> User-Agent: Mutt/1.9.5 (2018-04-13) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2018 16:24:24 -0000 On Wed, May 02, 2018 at 11:42:37AM -0400, Mark Johnston wrote: > On Wed, May 02, 2018 at 09:34:57AM -0600, Ian Lepore wrote: > > On Wed, 2018-05-02 at 11:20 -0400, Mark Johnston wrote: > > > Hi, > > > > > > We have a few pieces of code that follow a pattern: a thread > > > allocates a > > > resource and schedules a callout. The callout handler releases the > > > resource and never reschedules itself. In the common case, a thread > > > will cancel the callout before it executes. To know whether it must > > > release the resource associated with the callout, this thread must > > > know > > > whether the pending callout was cancelled. > > > > > > > It seems to me a better solution would be to track the state / lifetime > > of the resource separately rather than trying to infer the state of the > > resource from the state of the callout as viewed through a semi-opaque > > interface. > > > > If the original thread that schedules the callout keeps enough > > information about the resource to free it after cancelling, then it is > > already maintaining some kind of sideband info about the resource, even > > if it's just a pointer to be freed. Couldn't the callout routine > > manipulate this resource tracking info (null out the pointer or set a > > bool or whatever), then after cancelling you don't really care whether > > the callout ran or not, you just examine the pointer/bool/whatever and > > free or not based on that. > > I'd considered that. It's not quite as elegant a solution as you > suggest, since in my case the resource is embedded in an opaque > structure, so I need to add an extra field beside the callout to track > state that's already tracked by the callout subsystem. That plus the > fact that we have multiple instances of this bug make me want to fix it > in a general way, though I recognize that the callout API is already > overly complicated. I gave up on trying to get this fixed. r302350 was not the first time the return value was broken. I had to do r303426 exactly for this reason.