improve-shmem-init-callback-locking-docs.patch
text/x-patch
Filename: improve-shmem-init-callback-locking-docs.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| doc/src/sgml/xfunc.sgml | 2 | 2 |
| src/backend/storage/ipc/shmem.c | 5 | 2 |
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index bae16d7fb53..cb3cc09f16d 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -3739,8 +3739,8 @@ my_shmem_init(void *arg)
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>
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index f1f7cd3a4ff..1fbba9c3a4c 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -918,7 +918,10 @@ CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks)
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);
/*
@@ -937,7 +940,7 @@ CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks)
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