What behavior is in this loop?

Started by KONDO Mitsumasaalmost 12 years ago3 messages
#1KONDO Mitsumasa
kondo.mitsumasa@lab.ntt.co.jp

Hi,

I found interesting "for" and "while" loop in WaitForWALToBecomeAvailable() in
xlog.c. Can you tell me this behavior?

for (;;)
{
~
} while (StanbyMode)

I confirmed this code is no problem in gcc compiler:)

Regards,
--
Mitsumasa KONDO
NTT Open Source Software Center

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

#2Heikki Linnakangas
hlinnakangas@vmware.com
In reply to: KONDO Mitsumasa (#1)
Re: What behavior is in this loop?

On 02/27/2014 12:38 PM, KONDO Mitsumasa wrote:

I found interesting "for" and "while" loop in WaitForWALToBecomeAvailable() in
xlog.c. Can you tell me this behavior?

for (;;)
{
~
} while (StanbyMode)

I confirmed this code is no problem in gcc compiler:)

Oh wow :-). That's clearly a thinko, although harmless in this case.
Looking at the git history, I made that mistake in commit abf5c5c9a.
Before that, there was no "while".

That's easier to understand with some extra formatting. That's two
loops, like this:

/* loop 1 */
for (;;)
{
...
}

/* loop2 */
while(StandbyMode);

The second loop is obviously completely pointless. Thankfully, the there
are no "breaks" inside the first loop (the ones within the
switch-statements don't count), so the endless while-loop is never reached.

I'll go fix that... Thanks for the report!

- Heikki

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

#3KONDO Mitsumasa
kondo.mitsumasa@lab.ntt.co.jp
In reply to: Heikki Linnakangas (#2)
Re: What behavior is in this loop?

(2014/02/27 20:19), Heikki Linnakangas wrote:

On 02/27/2014 12:38 PM, KONDO Mitsumasa wrote:

I found interesting "for" and "while" loop in WaitForWALToBecomeAvailable() in
xlog.c. Can you tell me this behavior?

for (;;)
{
~
} while (StanbyMode)

I confirmed this code is no problem in gcc compiler:)

Oh wow :-). That's clearly a thinko, although harmless in this case. Looking at
the git history, I made that mistake in commit abf5c5c9a. Before that, there was
no "while".

That's easier to understand with some extra formatting. That's two loops, like this:

/* loop 1 */
for (;;)
{
...
}

/* loop2 */
while(StandbyMode);

The second loop is obviously completely pointless. Thankfully, the there are no
"breaks" inside the first loop (the ones within the switch-statements don't
count), so the endless while-loop is never reached.

Yeah, StandbyMode flag doesn't change in this loop.

I'll go fix that... Thanks for the report!

Thanks for your kind!

By the way, I found cannot promote problem in PG9.3.3 in standby mode with
archive revovery and crash recovery situations. I analyze this problem and fix it
now. Please take care of then!

Regards,
--
Mitsumasa KONDO
NTT Open Source Software Center

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