shared memory allocation - C function

Started by Alan Nilssonalmost 12 years ago3 messagesgeneral
Jump to latest
#1Alan Nilsson
anilsson@apple.com

Is it possible to allocate a small chunk of shared memory outside of any pools(i.e. manually alloced & de-alloced) that is visible to all processes? I would like a small amount to store a mutex and a condition variable that is accessible in a c function from any process. Is there an SPI/API to do this?

alan

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Michael Paquier
michael@paquier.xyz
In reply to: Alan Nilsson (#1)
Re: shared memory allocation - C function

On Thu, Apr 17, 2014 at 8:04 AM, Alan Nilsson <anilsson@apple.com> wrote:

Is it possible to allocate a small chunk of shared memory outside of any
pools(i.e. manually alloced & de-alloced) that is visible to all processes?
I would like a small amount to store a mutex and a condition variable that
is accessible in a c function from any process. Is there an SPI/API to do
this?

You can allocate a custom amount of shared memory at server initialization
using the hook called shmem_startup_hook in ipci.c through a library loaded
with shared_preload_libraries. Why not having a look at
contrib/pg_stat_statements which is a good example?
--
Michael

#3Alan Nilsson
anilsson@apple.com
In reply to: Michael Paquier (#2)
Re: shared memory allocation - C function

Perfect, thank you.

On Apr 16, 2014, at 9:56 PM, Michael Paquier <michael.paquier@gmail.com> wrote:

Show quoted text

On Thu, Apr 17, 2014 at 8:04 AM, Alan Nilsson <anilsson@apple.com> wrote:
Is it possible to allocate a small chunk of shared memory outside of any pools(i.e. manually alloced & de-alloced) that is visible to all processes? I would like a small amount to store a mutex and a condition variable that is accessible in a c function from any process. Is there an SPI/API to do this?
You can allocate a custom amount of shared memory at server initialization using the hook called shmem_startup_hook in ipci.c through a library loaded with shared_preload_libraries. Why not having a look at contrib/pg_stat_statements which is a good example?
--
Michael