From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 19 10:49:04 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BBC53775 for ; Thu, 19 Mar 2015 10:49:04 +0000 (UTC) Received: from mail-wi0-x236.google.com (mail-wi0-x236.google.com [IPv6:2a00:1450:400c:c05::236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46DCDCCE for ; Thu, 19 Mar 2015 10:49:04 +0000 (UTC) Received: by wifj2 with SMTP id j2so65116691wif.1 for ; Thu, 19 Mar 2015 03:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=LY/cOWuW4sZoT8vGC6mhqv0mYDiOutnsowDHg8woaKY=; b=VmznWS15uBVs/BaEjUFQPgZCKTTM3YEm581m9kjRd4HAen1X9Hkf6pUCax8x5CO588 V/OyHvNL7Qz328TkFntdfEjMpG3QeQjY+sdiU7S63GYrp79gUctQ6YVSYZAUtO+S/uSG xDAv1D3HNWfZU2EFT3H+LhI6VljnSBY7Gdms2kC4MJMLEvBg9QjjaNs3ZgVVSYyHPhNp CIJUGMsW5tcvTDKXAAzFlVArMRuB8vg81YlmnQAzmjsRkihWdDcoQrlBO82LAbHSGnR3 zG7anWpWYiQUUqJ8XGKomsbFyiDXjLY3FRZzPDMof86Cd+cGdHso0AnQ+reRqaMkJiWX dY/g== X-Received: by 10.181.9.107 with SMTP id dr11mr15520151wid.40.1426762142656; Thu, 19 Mar 2015 03:49:02 -0700 (PDT) Received: from zmaj.softwarehood.com (212-200-205-182.dynamic.isp.telekom.rs. [212.200.205.182]) by mx.google.com with ESMTPSA id hd10sm6982701wib.7.2015.03.19.03.49.01 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 03:49:01 -0700 (PDT) Message-ID: <550AA99C.5060102@gmail.com> Date: Thu, 19 Mar 2015 11:49:00 +0100 From: Ivan Radovanovic User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130812 Thunderbird/17.0.8 MIME-Version: 1.0 To: Konstantin Belousov Subject: Re: kevent behavior References: <550A6DA2.1070004@gmail.com> <20150319100151.GY2379@kib.kiev.ua> In-Reply-To: <20150319100151.GY2379@kib.kiev.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@FreeBSD.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2015 10:49:04 -0000 On 03/19/15 11:01, Konstantin Belousov napisa: > On Thu, Mar 19, 2015 at 07:33:06AM +0100, Ivan Radovanovic wrote: >> Hi guys, >> >> Is there defined (and guaranteed) behavior of kevent if kqueue FD is >> being closed while blocking kevent call is in progress? >> >> Possible scenario would be like this: >> >> Thread 1: >> ... >> kfd = kqueue(); >> ... >> // create second thread afterwords >> // and do blocking wait for events >> result = kevent(kfd, changelist, nchanges, eventlist, nevents, NULL); >> if (result == -1) >> // check if there was request to stop listening for events >> >> >> Thread 2: >> // do something >> // then close kqueue's fd >> close(kfd); >> >> >> I am asking this because file watcher implementation for mono is >> implemented that way (which I find nicer than using timeout), but this >> is apparently based on expected kevent behavior under Darwin, and I >> can't find any mention that in FreeBSD kevent is going to behave the >> same way (at least not on kqueue(2) manual page) > > The only special action taken by kqueue subsystem when a file descriptor > becomes invalid due to close, is the removal of all registered events > which reference the closing file descriptor. And, to prevent kqueue > code from stepping on its own toes, the close() call is put into > uninterruptible sleep with the "kqclose" wait channel until all > currently active kevent(2) calls release the references. > So if I understand you correctly close(kfd) would simply block because kevent on same kqueue descriptor is in progress?