Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWNpu-00019M-KG for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2020 18:00:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kWNpr-0001Wt-FC for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2020 18:00:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWNpr-0001Wi-6k for pgsql-bugs@lists.postgresql.org; Sat, 24 Oct 2020 18:00:11 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kWNpk-0002F8-Gg for pgsql-bugs@lists.postgresql.org; Sat, 24 Oct 2020 18:00:09 +0000 Received: by mail-lj1-x22b.google.com with SMTP id x16so5153607ljh.2 for ; Sat, 24 Oct 2020 11:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=sgMJmLG65sJJ3TXyLYgibFfaYE0cgkbPRUYlJyPT53o=; b=t7CrPYuZsbAsZnW6MlfD6l7/nvQ71vz23Vk1TfvJ936QDVnk7INe3wj/EAPXrkoj3D hzRjwcs/lq0GvLU3ZHKGIo8rw0+yMlZGUR71/IAdfnx8bm8ahwln38GapWIRPqI1LLAu PLJn6r+Oyi/0VM+AdjeZ1j6b9751cyE/eFtJXAFHZ9LhNcY4MFdFbzwWYmpTM/uLR9cp THek2wRzL5eAW5ZyRjfHg6HIJeNwEXm/edpMC7LvUaeDgyG5TMwgOB8Fgi4Tiwa7NuXd UqgQEej0kmTvr9mqn6VmqpLYH9ZMnVl65LZRq7BwjtI0Wba7PM+CcisBqqCYPV260CdW PwLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=sgMJmLG65sJJ3TXyLYgibFfaYE0cgkbPRUYlJyPT53o=; b=ABkACK/tSzeCrVAttH1Q82JjdFP4hrxuLMFuXNP2AEx6E+1eps4t1pF65EsV5QDtyb U88Tkl8Eie0Z/IPEkVSJoEXBBoFw8/SlBrNAIeYg85eLNsxJSHvcrg8S5b4lAM/AGPKY Xqro4yw9qrT9s3kZx2GT9ojn/uINNlHHObyDKcc2EihJoTMa82oXfkcKsDcGJI0WRmiM hzCi0+OC/fZ66NYoP8HoISpOb76DLBp114kl6v1QyiYCexW5VVTmSfZVpf6PGEoy28Rc izV/fsJUv5IDciZm2ltl/DCMwITQtk+mKPFpAwG1dGus439+MypRveoir0HZR4j72NvQ k+oA== X-Gm-Message-State: AOAM531HTNpMmpw7EfITTAfHcPgAwE2oOTBoWyA957aOXXAVl9pNXL2y yG0ea5ldHSD9n+5GhEioWaETevS3Zxs= X-Google-Smtp-Source: ABdhPJx1H7NcOjygm+ublaFtjDMODxMIxNDqRTrUiiZIDve8wR+9PAYbt/v5mafh6tbxARUp6eIauQ== X-Received: by 2002:a2e:8110:: with SMTP id d16mr2628542ljg.280.1603562402576; Sat, 24 Oct 2020 11:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.6.144]) by smtp.gmail.com with ESMTPSA id w2sm209888lfe.155.2020.10.24.11.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 Oct 2020 11:00:02 -0700 (PDT) Subject: Re: BUG #16685: The ecpg thread/descriptor test fails sometimes on Windows To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org References: <16685-d6cd241872c101d3@postgresql.org> <367782.1603554604@sss.pgh.pa.us> <380144.1603558463@sss.pgh.pa.us> From: Alexander Lakhin Message-ID: Date: Sat, 24 Oct 2020 21:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <380144.1603558463@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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