From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 21 19:43:03 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5DD8442A; Thu, 21 Nov 2013 19:43:03 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 379542FED; Thu, 21 Nov 2013 19:43:03 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 586F0B98A; Thu, 21 Nov 2013 14:43:02 -0500 (EST) From: John Baldwin To: freebsd-hackers@freebsd.org Subject: Re: taskqueue_block Date: Thu, 21 Nov 2013 14:14:06 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <5287BDB9.10201@FreeBSD.org> <528B7681.6090806@FreeBSD.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201311211414.06849.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 21 Nov 2013 14:43:02 -0500 (EST) Cc: Adrian Chadd , Andriy Gapon X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Nov 2013 19:43:03 -0000 On Tuesday, November 19, 2013 10:29:18 pm Adrian Chadd wrote: > Yes, and lets fix this. :) Hmm, is taskqueue_block() always used in context where waiting is safe? > On 19 November 2013 06:32, Andriy Gapon wrote: > > > > Forwarding this to the larger audience for a discussion. > > > > -------- Original Message -------- > > Message-ID: <5287BDB9.10201@FreeBSD.org> > > Date: Sat, 16 Nov 2013 20:47:21 +0200 > > From: Andriy Gapon > > Subject: taskqueue_block > > > > > > > > It seems that either I do not understand something about taskqueue_block code or > > it is a quite dangerous and abused API. The fact that it is not properly > > documented does not help either. > > > > The commit message said: > >> Implement taskqueue_block() and taskqueue_unblock(). These functions allow the > >> owner of a queue to block and unblock execution of the tasks in the queue while > >> allowing tasks to continue to be added queue. Combining this with > >> taskqueue_drain() allows a queue to be safely disabled. The unblock function may > > [...] > > > > I indeed see this (anti?) pattern being used in the code. > > But what about the following case. One thread calls taskqueue_block() and sets > > TQ_FLAGS_BLOCKED. Another thread calls taskqueue_enqueue, this adds a task to > > the queue and sets ta_pending of the task to 1. tq_enqueue is not called, so an > > actual queue runner is not called or waken up. Then the first thread calls > > taskqueue_drain() on the task. As far as I can see, the thread would then just > > wait forever because the task is pending and is not going to be executed. > > > > Additionally, it is impossible to reason about the taskqueue's state after > > taskqueue_block call, because the call just sets the flag and does not do any > > synchronization. And as described above, it is not safe to call APIs that could > > allow the taskqueue or the task state to become known. > > > > I think that taskqueue_block() should wait on the currently active tasks to > > complete. I don't think that this behavior could be optional. I do see any > > reasonable and safe use for "non-blocking" taskqueue_block(). > > taskqueue_drain() calls after taskqueue_block() must be removed. The code > > should either use taskqueue_drain() or "blocking" taskqueue_block() depending on > > concrete circumstances. > > > > What do you think? > > Thank you. > > -- > > Andriy Gapon > > > > > > > > _______________________________________________ > > freebsd-hackers@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > -- John Baldwin