Skip site navigation (1) Skip section navigation (2)

Re: Minor fix in lwlock.c

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Minor fix in lwlock.c
Date: 2005-04-08 14:04:19
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-patches
"Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu> writes:
> /* Unlock semaphores first */
> while (extraWaits-- > 0)
>     PGSemaphoreUnlock(&proc->sem);

> /* Add the lock into my list then.
>  * If a process is in exiting status, it could use the reserved lwlocks
>  */
> reserved = proc_exit_inprogress? 0 : NUM_RESERVED_LWLOCKS;
> if (num_held_lwlocks >= MAX_SIMUL_LWLOCKS - reserved)
>     elog(ERROR, "too many LWLocks taken");
> held_lwlocks[num_held_lwlocks++] = lockid;

But if the MAX_SIMUL_LWLOCKS - NUM_RESERVED_LWLOCKS limit is reached,
you elog without having recorded the lock you just took ... which is a
certain loser since nothing will ever release it.  Also,
proc_exit_inprogress is not the appropriate thing to test for unless
you're going to use an elog(FATAL).

I think it would work to record the lock, unwind the extraWaits, and
*then* elog if we're above the allowable limit.  Something like

 if (num_held_lwlocks >= MAX_SIMUL_LWLOCKS)
     elog(PANIC, "too many LWLocks taken");
 held_lwlocks[num_held_lwlocks++] = lockid;

 while (extraWaits-- > 0)

 if (!InError && num_held_lwlocks >= MAX_SIMUL_LWLOCKS - NUM_RESERVED_LWLOCKS)
     elog(ERROR, "too many LWLocks taken");

except we don't have the InError flag anymore so there'd need to be some
other test for deciding whether it should be OK to go into the reserved

But I think this is too much complexity for a case that shouldn't ever

			regards, tom lane

In response to

pgsql-patches by date

Next:From: Tom LaneDate: 2005-04-08 14:19:02
Subject: Re: Minor fix in lwlock.c
Previous:From: Qingqing ZhouDate: 2005-04-08 07:58:52
Subject: Re: Minor fix in lwlock.c

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group