pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Detect double-release of spinlock
Date: Mon, 29 Jul 2024 21:00:35 +0300
Message-ID: <790b901f-c0f6-4e97-b59a-97d8f921d57e@iki.fi> (raw)
In-Reply-To: <20240729174853.uo5qjqkxlacjg6vv@awork3.anarazel.de>
References: <E1sYSF2-001lEB-D1@gemulon.postgresql.org>
	<2600757.1722267116@sss.pgh.pa.us>
	<20240729161846.kgiafbe2dtgabxgb@awork3.anarazel.de>
	<2802449.1722270793@sss.pgh.pa.us>
	<20240729164026.yurg37tej34o76uk@awork3.anarazel.de>
	<20240729165154.56zqyg34x2ywkpsh@awork3.anarazel.de>
	<e8d4ef94-b8aa-4cda-8f31-081f78194275@iki.fi>
	<2809049.1722273922@sss.pgh.pa.us>
	<20240729174853.uo5qjqkxlacjg6vv@awork3.anarazel.de>

On 29/07/2024 20:48, Andres Freund wrote:
> On 2024-07-29 13:25:22 -0400, Tom Lane wrote:
>> Heikki Linnakangas <hlinnaka@iki.fi> writes:
>>> Yeah I'm not worried about that at all. Also, the assert is made when
>>> you have already released the spinlock; you are already out of the
>>> critical section.
>>
>> Not in the patch Andres posted.
> 
> Which seems fairly fundamental - once outside of the critical section, we
> can't actually assert that the lock isn't acquired, somebody else *validly*
> might have acquired it by then.

You could do:

bool was_free = S_LOCK_FREE(lock);

S_UNLOCK(lock);
Assert(!was_free);

Depending on the underlying implementation, you could also use 
compare-and-exchange. That makes the assertion-enabled instructions a 
little different than without assertions though.

> However, I still don't think it's a problem to assert that the lock is held in
> in the unlock "routine". As mentioned before, the spinlock implementation
> itself has never followed the "just straight line code" rule that users of
> spinlocks are supposed to follow.

Agreed.

-- 
Heikki Linnakangas
Neon (https://neon.tech)






view thread (8+ messages)  latest in thread

Message-ID: <790b901f-c0f6-4e97-b59a-97d8f921d57e@iki.fi>
Permalink:  ../790b901f-c0f6-4e97-b59a-97d8f921d57e@iki.fi/
Also on:    postgresql.org/message-id/790b901f-c0f6-4e97-b59a-97d8f921d57e@iki.fi

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: hlinnaka@iki.fi, andres@anarazel.de, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
  Subject: Re: Detect double-release of spinlock
  In-Reply-To: <790b901f-c0f6-4e97-b59a-97d8f921d57e@iki.fi>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox