From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 20 03:29:19 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4639F2B6; Wed, 20 Nov 2013 03:29:19 +0000 (UTC) Received: from mail-qc0-x22f.google.com (mail-qc0-x22f.google.com [IPv6:2607:f8b0:400d:c01::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EF859279A; Wed, 20 Nov 2013 03:29:18 +0000 (UTC) Received: by mail-qc0-f175.google.com with SMTP id v14so581658qcr.20 for ; Tue, 19 Nov 2013 19:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=wjFe0RBd38gPvx7Bw5sjzObiqXdAH4uBkHG1bXKx1ww=; b=U1S8S19+K92GOasO33KHE9kRWYbcQxS10ZLYip7H76LGRd/8FfUQT9CCgBP0v2sZg4 7NByFN0nxTnRnpmH3huyUOS+gAgkemwK1LhLphs5nBkbqmdjy+5p6vgvabl0RBu2g9o1 UHyhTSI7G67lrFzfY97fnpTWyVVVJi5wIp7l8iQ6O18P0kB/oBPYXZ/DRmQ7d4a1K6mf KgzoNwqovGljXP//EU2NeEtUSHMYE85AAJuKPtOWEhHIygIEQmPqXYPxKcua4qKE8KMp +gizYug8RB+AWRvsLFvDNXQU9lqR4riJgQRrXDgLpWEHwGcoVdlNgexlwubsiyeyX0Cw YtqA== MIME-Version: 1.0 X-Received: by 10.49.59.70 with SMTP id x6mr48743897qeq.17.1384918158152; Tue, 19 Nov 2013 19:29:18 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.224.207.66 with HTTP; Tue, 19 Nov 2013 19:29:18 -0800 (PST) In-Reply-To: <528B7681.6090806@FreeBSD.org> References: <5287BDB9.10201@FreeBSD.org> <528B7681.6090806@FreeBSD.org> Date: Tue, 19 Nov 2013 19:29:18 -0800 X-Google-Sender-Auth: I80uT54wLwfHYondPdSMYGqSQ0I Message-ID: Subject: Re: taskqueue_block From: Adrian Chadd To: Andriy Gapon Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-hackers@freebsd.org" 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: Wed, 20 Nov 2013 03:29:19 -0000 Yes, and lets fix this. :) -a 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"