Re: shmem_startup_hook called twice on Windows - Mailing list pgsql-hackers

From Sami Imseih
Subject Re: shmem_startup_hook called twice on Windows
Date
Msg-id CAA5RZ0uM4o82w6KHoy6+PtEaYsX3Tszp96ZUXHabTs0ax=+gqA@mail.gmail.com
Whole thread Raw
In response to Re: shmem_startup_hook called twice on Windows  (Nathan Bossart <nathandbossart@gmail.com>)
List 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



pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: Improve LWLock tranche name visibility across backends
Next
From: Sami Imseih
Date:
Subject: Re: Improve LWLock tranche name visibility across backends