Re: shmem_startup_hook called twice on Windows

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: shmem_startup_hook called twice on Windows
Date: 2025-08-18 22:05:00
Message-ID: CAA5RZ0uM4o82w6KHoy6+PtEaYsX3Tszp96ZUXHabTs0ax=+gqA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > "Because this hook is executed by the postmaster and invoked by backends via
> > EXEC_BACKEND, it is essential to ensure that any code intended to run only
> > during postmaster startup is properly protected against repeated execution.
> > This can be enforced by verifying !IsUnderPostmaster before invocation."
>
> IMHO we should avoid talking about EXEC_BACKEND, etc. and instead make it
> clear that hooks should be prepared to deal with concurrent invocations
> from other backends. But taking a step back, I'm still not entirely clear
> what this adds to the existing documentation, which is pretty direct about
> the need for locking and how to avoid re-initializing.

I am not sure. I read this

""
If this function sets foundPtr to false, the caller should proceed to
initialize the contents of the reserved shared memory. If foundPtr is
set to true,
the shared memory was already initialized by another backend, and the caller
need not initialize further.
"""

and it's related to ShmemInitStruct specifically.

Imagine someone adds some code in there that does more than just
ShmemInitStruct. This code will be run multiple times on EXEC_BACKEND
vs once on !EXEC_BACKEND

IMO, that is quite a large difference in behavior that should be clearly noted.

--
Sami

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Sami Imseih 2025-08-18 22:53:44 Re: Improve LWLock tranche name visibility across backends
Previous Message Nathan Bossart 2025-08-18 21:42:09 Re: Improve LWLock tranche name visibility across backends