]> git.ipfire.org Git - thirdparty/postgresql.git/commit
De-pessimize ConditionVariableCancelSleep().
authorThomas Munro <tmunro@postgresql.org>
Mon, 14 Aug 2023 22:20:11 +0000 (10:20 +1200)
committerThomas Munro <tmunro@postgresql.org>
Mon, 14 Aug 2023 22:33:55 +0000 (10:33 +1200)
commitacc5c4fd8f83e5991cab11d7299d112e89cb3fe7
tree94e040ff5e5f7a184cc20b4ea56a74c90224b0d4
parent03fb43f6ed63fd2d52bf8ec305893a31ef0a38e5
De-pessimize ConditionVariableCancelSleep().

Commit b91dd9de was concerned with a theoretical problem with our
non-atomic condition variable operations.  If you stop sleeping, and
then cancel the sleep in a separate step, you might be signaled in
between, and that could be lost.  That doesn't matter for callers of
ConditionVariableBroadcast(), but callers of ConditionVariableSignal()
might be upset if a signal went missing like this.

Commit bc971f4025c interacted badly with that logic, because it doesn't
use ConditionVariableSleep(), which would normally put us back in the
wait list.  ConditionVariableCancelSleep() would be confused and think
we'd received an extra signal, and try to forward it to another backend,
resulting in wakeup storms.

New idea: ConditionVariableCancelSleep() can just return true if we've
been signaled.  Hypothetical users of ConditionVariableSignal() would
then still have a way to deal with rare lost signals if they are
concerned about that problem.

Back-patch to 16, where bc971f4025c arrived.

Reported-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/2840876b-4cfe-240f-0a7e-29ffd66711e7%40enterprisedb.com
src/backend/storage/lmgr/condition_variable.c
src/include/storage/condition_variable.h