Re: Contrib -- PostgreSQL shared variables

From: Thomas Hallgren <thhal(at)mailblocks(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Contrib -- PostgreSQL shared variables
Date: 2004-08-25 21:42:01
Message-ID: 412D07A9.7020404@mailblocks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

pgsql(at)mohawksoft(dot)com wrote:
> This is a first pass on a simple shared memory variable system for
> PostgreSQL. I would appriciate anyone interested in this functionality to
> rip it apart.
>
> It basically adds this functionality:
>
> SetShared('name', value);
> GetSharedInt('name');
> SetSharedText('name);
> RemovedShared('name');
>
> I also added two extra functions that are sort of a kludge, but could be
> very helpful.
>
> AddSharedInt('name', value);
> SubSharedInt('name', value);
>
> These add or subtect the 'value' from the variable and return the result.
>
Something that I've found very useful when dealing with shared memory is
the ability to do atomic exchange of values. With that in place, its
possible to perform atomic operations involving several variables.

Perhaps it could be as simple as splitting your SetShared into
SetSharedInt and SetSharedString and then have them return the old value?

Here's an example of what I mean (I use C syntax for clarity, I know the
intended use is from SQL).

/* Loop until something other than LOCKED is returned. When
* that happens, we have the lock.
*/
while(SetSharedInt('lock', LOCKED) == LOCKED)
usleep(WAIT_PERIOD);

Set a group of variables here.

/* Unlock
*/
SetSharedInt('lock', UNLOCKED);

Regards,

Thomas Hallgren

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2004-08-25 21:44:22 Re: [COMMITTERS] pgsql-server: Rearrange pg_subtrans handling
Previous Message Tom Lane 2004-08-25 21:35:02 Re: printing HeapTuple

Browse pgsql-patches by date

  From Date Subject
Next Message pgsql 2004-08-25 21:47:28 Re: Contrib -- PostgreSQL shared variables
Previous Message Ed L. 2004-08-25 21:26:29 log_line_prefix additions