From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Condition variable live lock
Date: Fri, 05 Jan 2018 01:10:57 -0500
Message-ID: <21761.1515132657@sss.pgh.pa.us> (raw)
In-Reply-To: <CAEepm=10Es09VfW656CXMnN0LENrAD4Z1Pn8Uxb9rpmDp+0i3Q@mail.gmail.com>
References: <CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com>
<CAEepm=1_S2Ly3Q53yViq29RVJmvaUw8hXs5_ekg_E1uHrNtXGQ@mail.gmail.com>
<20171229193843.tsbob2xsjfmxkq2g@alap3.anarazel.de>
<CA+TgmoZykfhWOQWqFcCHL2a-=QVigssd0og1x2AU6jtJsLN-iw@mail.gmail.com>
<20180104205447.mdaub47aunp3h3mq@alap3.anarazel.de>
<17054.1515126429@sss.pgh.pa.us>
<CAEepm=10Es09VfW656CXMnN0LENrAD4Z1Pn8Uxb9rpmDp+0i3Q@mail.gmail.com>
Thomas Munro <thomas.munro@enterprisedb.com> writes:
> On Fri, Jan 5, 2018 at 5:27 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Now, the limitation with this is that we can't be waiting for any *other*
>> condition variable, because then we'd be trashing our state about that
>> variable. As coded, we can't be waiting for the target CV either, but
>> that case could actually be handled if we needed to, as per the comment.
>> I do not know if this is likely to be a problematic limitation
>> ... discuss. (The patch does survive check-world, FWIW.)
> ... one way to lift the restriction would
> be to teach ConditionVariableBroadcast() to call
> ConditionVariableCancelSleep() if cv_sleep_target is non-NULL where
> you have the current assertion. Code that is still waiting for a CV
> must be in a loop that will eventually re-add it in
> ConditionVariableSleep(), and it won't miss any signals that it can't
> afford to miss because the first call to ConditionVariableSleep() will
> return immediately so the caller will recheck its condition.
Oh, of course, very simple.
I thought of another possible issue, though. In the situation where
someone else has removed our sentinel (presumably, by issuing
ConditionVariableSignal just before we were about to remove the
sentinel), my patch assumes we can just do nothing. But it seems
like that amounts to losing one signal. Whoever the someone else
was probably expected to awaken a waiter, and now that won't happen.
Should we rejigger the logic so that it awakens one additional waiter
(if there is one) after detecting that someone else has removed the
sentinel? Obviously, this trades a risk of loss of wakeup for a risk
of spurious wakeup, but presumably the latter is something we can
cope with.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, thomas.munro@enterprisedb.com, andres@anarazel.de, robertmhaas@gmail.com
Subject: Re: Condition variable live lock
In-Reply-To: <21761.1515132657@sss.pgh.pa.us>
References: <CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com> <CAEepm=1_S2Ly3Q53yViq29RVJmvaUw8hXs5_ekg_E1uHrNtXGQ@mail.gmail.com> <20171229193843.tsbob2xsjfmxkq2g@alap3.anarazel.de> <CA+TgmoZykfhWOQWqFcCHL2a-=QVigssd0og1x2AU6jtJsLN-iw@mail.gmail.com> <20180104205447.mdaub47aunp3h3mq@alap3.anarazel.de> <17054.1515126429@sss.pgh.pa.us> <CAEepm=10Es09VfW656CXMnN0LENrAD4Z1Pn8Uxb9rpmDp+0i3Q@mail.gmail.com> <21761.1515132657@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox