pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16685: The ecpg thread/descriptor test fails sometimes on Windows
Date: Sat, 24 Oct 2020 21:00:00 +0300
Message-ID: <dedbf623-ae82-5635-a639-944395697799@gmail.com> (raw)
In-Reply-To: <380144.1603558463@sss.pgh.pa.us>
References: <16685-d6cd241872c101d3@postgresql.org>
	<367782.1603554604@sss.pgh.pa.us>
	<380144.1603558463@sss.pgh.pa.us>

24.10.2020 19:54, Tom Lane wrote:
> I'm forced to the conclusion that there's something wrong with
> ECPG's emulation of pthread_once ...
>
> ... and now that I look at it, it seems just as obvious what
> is wrong there:
>
> void
> win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void))
> {
> 	if (!*once)
> 	{
> 		pthread_mutex_lock(&win32_pthread_once_lock);
> 		if (!*once)
> 		{
> 			*once = true;
> 			fn();
> 		}
> 		pthread_mutex_unlock(&win32_pthread_once_lock);
> 	}
> }
>
> We should not set *once until AFTER we execute fn().
> Otherwise, other threads passing through pthread_once()
> will mistakenly fall through, expecting the initialization
> to be done already.
>
> (So in this view, adding a sleep just before fn() would
> make the failure more reproducible.)
Yes, adding "pg_usleep(1000L);" just before fn() leads to 15 of 100
tests failed (without the delay more than 100 iterations could pass
successfully).
And the reverse test construction:
            fn();
            pg_usleep(1000L);
            *once = true;
Makes all the tests (I ran 30x100 iterations) pass just fine.
Thank you for looking into this!

Best regards,
Alexander





view thread (5+ messages)  latest in thread

Message-ID: <dedbf623-ae82-5635-a639-944395697799@gmail.com>
Permalink:  ../dedbf623-ae82-5635-a639-944395697799@gmail.com/
Also on:    postgresql.org/message-id/dedbf623-ae82-5635-a639-944395697799@gmail.com

 · 

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-bugs@postgresql.org
  Cc: exclusion@gmail.com, tgl@sss.pgh.pa.us, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16685: The ecpg thread/descriptor test fails sometimes on Windows
  In-Reply-To: <dedbf623-ae82-5635-a639-944395697799@gmail.com>

* 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