Make it explicit in the docs that the shmem initialization callbacks
are called while holding ShmemIndexLock.
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5sHs+eSiTDOd14buayc6JbBX=Hm5ssFMBK0Ki9sTGEOuA@mail.gmail.com
Backpatch-through: 19
startup, it will immediately call the appropriate callbacks, depending
on whether the requested memory areas were already initialized by
another backend. The callbacks will be called while holding an internal
- lock, which prevents concurrent two backends from initializing the
- memory area concurrently.
+ lock (ShmemIndexLock), which prevents the race condition of two backends
+ trying to initializing the memory area at the same time.
</para>
</sect3>
return;
}
- /* Hold ShmemIndexLock while we allocate all the shmem entries */
+ /*
+ * Hold ShmemIndexLock while we allocate all the shmem entries and run all
+ * the initializers.
+ */
LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
/*
notfound_any = true;
}
if (found_any && notfound_any)
- elog(ERROR, "found some but not all");
+ elog(ERROR, "some of the requested shmem areas have already been initialized");
/*
* Allocate or attach all the shmem areas requested by the request_fn