Re: shadow variables - pg15 edition

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>, Peter Smith <smithpb2250(at)gmail(dot)com>
Subject: Re: shadow variables - pg15 edition
Date: 2022-10-06 20:13:31
Message-ID: CAApHDvpch0y+4DjFJTvfBWfOaBPx-LS6Spoamm0mi2JAOWf7_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 6 Oct 2022 at 20:32, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
>
> On 2022-Oct-06, David Rowley wrote:
> > I didn't want to do it that way because all this code is in a while
> > loop and the outer "now" will be reused after it's set by the code
> > above. It's not really immediately obvious to me what repercussions
> > that would have, but it didn't seem worth taking any risks.
>
> No, it's re-initialized to zero every time through the loop, so setting
> it to something else at the bottom doesn't have any further effect.

Oh yeah, you're right.

> If it were *not* reinitialized every time through the loop, then what
> would happen is that every iteration in the loop (and each operation
> within) would see exactly the same value of "now", because it's only set
> "lazily" (meaning, if already set, don't change it.)

On my misread, that's what I was afraid of changing, but now seeing
that now = 0 at the start of each loop, I understand that
pg_time_now_lazy will get an up-to-date time on each loop.

I'm happy if you want to change it to use the outer scoped variable
instead of the now2 one.

David

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2022-10-06 20:44:49 Re: Reducing the chunk header sizes on all memory context types
Previous Message Andres Freund 2022-10-06 20:11:31 Re: [PATCH v1] [meson] fix some typo to make it more readable