Thomas Munro <thomas.munro@gmail.com> writes:
> (Hmm, I wonder about that Windows process exit event.)
If anyone wants to test that, I can save you a little time building
infrastructure, perhaps. I used the attached program built into a .so.
After creating the function, invoke it, and once it's blocked kill -9
the postmaster. If it successfully reports multiple WL_POSTMASTER_DEATH
results then it's good.
regards, tom lane
/*
create function wait_on_process_latch() returns void
strict volatile language c as '.../whatever.so';
select wait_on_process_latch();
*/
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "storage/latch.h"
#include "pgstat.h"
PG_MODULE_MAGIC;
/*
* wait_on_process_latch() returns void
*/
PG_FUNCTION_INFO_V1(wait_on_process_latch);
Datum
wait_on_process_latch(PG_FUNCTION_ARGS)
{
int count = 10;
while (count-- > 0)
{
int rc;
CHECK_FOR_INTERRUPTS();
elog(INFO, "waiting on latch");
rc = WaitLatch(MyLatch,
WL_LATCH_SET | WL_POSTMASTER_DEATH, 0,
WAIT_EVENT_BGWORKER_SHUTDOWN);
if (rc & WL_POSTMASTER_DEATH)
{
elog(INFO, "got WL_POSTMASTER_DEATH report");
}
ResetLatch(MyLatch);
}
PG_RETURN_VOID();
}