shm_mq: Fix detach race condition.
shm_mq: Fix detach race condition.

Commit 34db06ef9a1d7f36391c64293bf1e0ce44a33915 adopted a lock-free
design for shm_mq.c, but it introduced a race condition that could
lose messages.  When shm_mq_receive_bytes() detects that the other end
has detached, it must make sure that it has seen the final version of
mq_bytes_written, or it might miss a message sent before detaching.

Thomas Munro

Discussion: https://postgr.es/m/CAEepm%3D2myZ4qxpt1a%3DC%2BwEv3o188K13K3UvD-44FK0SdAzHy%2Bw%40mail.gmail.com

adam8157/gpdb,lisakowen/gpdb,xinzweb/gpdb,50wu/gpdb,adam8157/gpdb,xinzweb/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,xinzweb/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,50wu/gpdb,greenplum-db/gpdb,50wu/gpdb,greenplum-db/gpdb,lisakowen/gpdb,50wu/gpdb,50wu/gpdb,lisakowen/gpdb,xinzweb/gpdb,lisakowen/gpdb,adam8157/gpdb,lisakowen/gpdb,xinzweb/gpdb,greenplum-db/gpdb,50wu/gpdb,adam8157/gpdb,50wu/gpdb,xinzweb/gpdb,lisakowen/gpdb,adam8157/gpdb,adam8157/gpdb,adam8157/gpdb,xinzweb/gpdb,lisakowen/gpdb,lisakowen/gpdb,greenplum-db/gpdb,adam8157/gpdb,xinzweb/gpdb,50wu/gpdb