Re: Condition variable live lock
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Andres Freund <andres@anarazel.de>, Robert Haas <robertmhaas@gmail.com>,
Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2018-01-05T06:10:57Z
Lists: pgsql-hackers
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
Commits
-
Add WL_EXIT_ON_PM_DEATH pseudo-event.
- cfdf4dc4fc96 12.0 landed
-
While waiting for a condition variable, detect postmaster death.
- 80259d4dbf47 11.0 landed
- d56a5f994c21 10.2 landed
-
Fix race condition during replication origin drop.
- 8a906204aec4 11.0 landed
- 1f5adbd799cf 10.2 landed
-
Allow ConditionVariable[PrepareTo]Sleep to auto-switch between CVs.
- 4af2190eb04b 10.2 landed
- 13db3b936359 11.0 landed
-
Cosmetic improvements in condition_variable.[hc].
- e35dba475a44 11.0 landed
-
Improve error detection capability in proclists.
- ea8e1bbc5384 11.0 landed
-
Remove return values of ConditionVariableSignal/Broadcast.
- ccf312a4488a 11.0 landed
-
Reorder steps in ConditionVariablePrepareToSleep for more safety.
- 83fe2708d668 10.2 landed
- 3cac0ec85992 11.0 landed
-
Rewrite ConditionVariableBroadcast() to avoid live-lock.
- aced5a92bf46 11.0 landed
- 1c77e990833a 10.2 landed
-
Add parallel-aware hash joins.
- 1804284042e6 11.0 cited