Hello,
Postgres today doesn't support waiting for a condition variable with a
timeout, although the framework it relies upon, does. This change wraps
the existing ConditionVariableSleep functionality and introduces a new
API, ConditionVariableTimedSleep, to allow callers to specify a timeout
value.
A scenario that highlights this use case is a backend is waiting on
status update from multiple workers but needs to time out if that signal
doesn't arrive within a certain period. There was a workaround prior
to aced5a92, but with that change, the semantics are now different.
I chose to go with -1 instead of 0 for the return from
ConditionVariableTimedSleep to indicate timeout error as it seems
cleaner for this API. WaitEventSetWaitBlock returns -1 for timeout but
WaitEventSetWait treats timeout as 0 (to represent 0 events indicating
timeout).
If there's an alternative, cleaner way to achieve this outcome, I am all
ears.
Thanks.
--
Shawn Debnath
Amazon Web Services (AWS)