Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Hm9-0006ge-7R for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Mar 2019 22:27:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5Hm5-00068v-Uu for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Mar 2019 22:27:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Hm5-00068i-Hd for pgsql-hackers@lists.postgresql.org; Sat, 16 Mar 2019 22:27:29 +0000 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Hm2-0008T5-93 for pgsql-hackers@postgresql.org; Sat, 16 Mar 2019 22:27:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1552775246; x=1584311246; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=OrxXFN7S3cI2+w8EmiPEShhqLqYSouatAGyxUo9fkJI=; b=LBL3ZHJQUANznoDSjH2tg5p3DsrdMsQSNQhf/mhNawotWFQTIYydd33R sWyCQXf6HAMDqRG/7qyJ6KJb87npdUYt/ogTCwd6tsuBDcIT2ySxYxRtz Jla840xogZCKgSEkoAAOuoCJSl7if/Obmci9VMag/gFykGce7Pvby1o6y E=; X-IronPort-AV: E=Sophos;i="5.58,487,1544486400"; d="scan'208";a="665482802" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1e-57e1d233.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Mar 2019 22:27:22 +0000 Received: from EX13MTAUWC001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-57e1d233.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x2GMRFEj014470 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sat, 16 Mar 2019 22:27:21 GMT Received: from EX13D05UWC002.ant.amazon.com (10.43.162.92) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Mar 2019 22:27:19 +0000 Received: from f01898859afd.ant.amazon.com (10.43.160.156) by EX13D05UWC002.ant.amazon.com (10.43.162.92) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Mar 2019 22:27:18 +0000 Date: Sat, 16 Mar 2019 15:27:17 -0700 From: Shawn Debnath To: Kyotaro HORIGUCHI CC: , Subject: Re: Introduce timeout capability for ConditionVariableSleep Message-ID: <20190316222717.GA2139@f01898859afd.ant.amazon.com> References: <20190313005342.GA8301@f01898859afd.ant.amazon.com> <20190313.172415.156658364.horiguchi.kyotaro@lab.ntt.co.jp> <20190315002611.GA1119@f01898859afd.ant.amazon.com> <20190315.141517.229371570.horiguchi.kyotaro@lab.ntt.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20190315.141517.229371570.horiguchi.kyotaro@lab.ntt.co.jp> User-Agent: Mutt/1.11.3 (2019-02-01) X-Originating-IP: [10.43.160.156] X-ClientProxiedBy: EX13D08UWC004.ant.amazon.com (10.43.162.90) To EX13D05UWC002.ant.amazon.com (10.43.162.92) Precedence: Bulk List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Mar 15, 2019 at 02:15:17PM +0900, Kyotaro HORIGUCHI wrote: > > After thinking about this more, I see WaitEventSetWait()'s contract > > as wait for an event or timeout if no events are received in that > > time > > Sure. > > > frame. Although ConditionVariableTimedSleep() is also using the same > > word, I believe the semantics are different. The timeout period in > > ConditionVariableTimedSleep() is intended to limit the time we wait > > until removal from the wait queue. Whereas, in the case of > > WaitEventSetWait, the timeout period is intended to limit the time the > > caller waits till the first event. > > Mmm. The two look the same to me.. Timeout means for both that > "Wait for one of these events or timeout expiration to > occur". Removal from waiting queue is just a subtask of exiting > from waiting state. > > The "don't exit until timeout expires unless any expected events > occur" part is to be done in the uppermost layer so it is enough > that the lower layer does just "exit when something > happened". Agree with the fact that lower layers should return and let the upper layer determine and filter events as needed. > This is the behavior of WaitEventSetWaitBlock for > WaitEventSetWait. My proposal is giving callers capabliy to tell > WaitEventSetWait not to perform useless timeout contination. This is where I disagree. WaitEventSetWait needs its own loop and timeout calculation because WaitEventSetWaitBlock can return when EINTR is received. This gets filtered in WaitEventSetWait and doesn't bubble up by design. Since it's involved in filtering events, it now also has to manage the timeout value. ConditionVariableTimedSleep being at a higher level, and waitng for certain events that the lower layers are unaware of, also shares the timeout management reponsibility. Do note that there is no performance impact of having multiple timeout loops. The current design allows for each layer to filter events and hence per layer timeout management seems fine. If one would want to avoid this, perhaps we need to introduce a non-static version of WaitEventSetWaitBlock and call that directly. But that of course is beyond this patch. > Thank you . It looks fine execpt the above point. But still I > have some questions on it. (the reason for they not being > comments is that they are about wordings..). > > + * Track the current time so that we can calculate the remaining timeout > + * if we are woken up spuriously. > > I think tha "track" means chasing a moving objects. So it might > be bettter that it is record or something? > > > * Wait for the given condition variable to be signaled or till timeout. > > * > > * Returns -1 when timeout expires, otherwise returns 0. > > * > > * See ConditionVariableSleep() for general usage. > > > > > +ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, > > > > > > Counldn't the two-state return value be a boolean? I will change it to Record in the next iteration of the patch. -- Shawn Debnath Amazon Web Services (AWS)