Fix status reporting for terminated bgworkers that were never started.
Fix status reporting for terminated bgworkers that were never started.

Previously, GetBackgroundWorkerPid() would return BGWH_NOT_YET_STARTED
if the slot used for the worker registration had not been reused by
unrelated activity, and BGWH_STOPPED if it had.  Either way, a process
that had requested notification when the state of one of its
background workers changed did not receive such notifications.  Fix
things so that GetBackgroundWorkerPid() always returns BGWH_STOPPED in
this situation, so that we do not erroneously give waiters the
impression that the worker will eventually be started; and send
notifications just as we would if the process terminated after having
been started, so that it's possible to wait for the postmaster to
process a worker termination request without polling.

Discovered by Amit Kapila during testing of parallel sequential scan.
Analysis and fix by me.  Back-patch to 9.4; there may not be anyone
relying on this interface yet, but if anyone is, the new behavior is a
clear improvement.

xinzweb/gpdb,xinzweb/gpdb,50wu/gpdb,zeroae/postgres-xl,50wu/gpdb,jmcatamney/gpdb,adam8157/gpdb,jmcatamney/gpdb,50wu/gpdb,ovr/postgres-xl,techdragon/Postgres-XL,yazun/postgres-xl,zeroae/postgres-xl,xinzweb/gpdb,pavanvd/postgres-xl,ovr/postgres-xl,oberstet/postgres-xl,techdragon/Postgres-XL,jmcatamney/gpdb,50wu/gpdb,adam8157/gpdb,pavanvd/postgres-xl,ovr/postgres-xl,greenplum-db/gpdb,pavanvd/postgres-xl,lisakowen/gpdb,lisakowen/gpdb,adam8157/gpdb,techdragon/Postgres-XL,ashwinstar/gpdb,50wu/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,zeroae/postgres-xl,zeroae/postgres-xl,Postgres-XL/Postgres-XL,Postgres-XL/Postgres-XL,greenplum-db/gpdb,Postgres-XL/Postgres-XL,Postgres-XL/Postgres-XL,lisakowen/gpdb,ashwinstar/gpdb,adam8157/gpdb,jmcatamney/gpdb,ovr/postgres-xl,pavanvd/postgres-xl,greenplum-db/gpdb,techdragon/Postgres-XL,greenplum-db/gpdb,jmcatamney/gpdb,zeroae/postgres-xl,oberstet/postgres-xl,jmcatamney/gpdb,yazun/postgres-xl,oberstet/postgres-xl,oberstet/postgres-xl,xinzweb/gpdb,50wu/gpdb,techdragon/Postgres-XL,ashwinstar/gpdb,Postgres-XL/Postgres-XL,yazun/postgres-xl,lisakowen/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,lisakowen/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,xinzweb/gpdb,pavanvd/postgres-xl,50wu/gpdb,adam8157/gpdb,ashwinstar/gpdb,lisakowen/gpdb,xinzweb/gpdb,jmcatamney/gpdb,adam8157/gpdb,adam8157/gpdb,lisakowen/gpdb,lisakowen/gpdb,adam8157/gpdb,ashwinstar/gpdb,xinzweb/gpdb,greenplum-db/gpdb,ovr/postgres-xl,50wu/gpdb,yazun/postgres-xl,yazun/postgres-xl,xinzweb/gpdb,oberstet/postgres-xl