delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2026/10/03/04:14:09

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 6938E8FS064753
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 6938E8FS064753
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=STUgNtIr
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EA174BA901D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1791015231;
bh=0MVtoBN5LqOCHTukEuA17fqvsThzMB0cfwwpsjfvL20=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=STUgNtIrcF4QnlWdp8Wf55ZKiGxf78o6CN2L8HXxtglM26APYx/lpaFCUz4cE1b1L
Q89/svHCGYC/Y6liQz81wPSHWXtLcAxtdb5YA+8mrm6ahtJ3I+aRJ6Er1CwpQJEHmN
G64qIYYXf3iB5cUGEG5zmrYB4wRT5wYzZtZ2S6rw=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2233E4BA79BC
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2233E4BA79BC
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791015182; cv=none;
b=bPPZWP1aktJi0ULd1vakuMCCJ8ydVuJxAHv4KO3Oz5ZAB0BFs7nYZDZ/8reu4oSvUF9Fwqz7cYhSP9fSihWBm/ZaPEWCsf0IAZgA75ss8fev5XL/EaJ1qpgU27PScKXwH3qxf1VpRaOkB80uOzuISgwronR0NtWS3RJEk1Mwv0Y=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1791015182; c=relaxed/simple;
bh=eaEy3iRXvioVLgVseE/iwBflumZzbnl/LvWuMPRyVh4=;
h=Message-ID:Date:MIME-Version:Subject:To:From;
b=gER/ogA4OU8ohjMUQsu2T8iQaBqX/hcjEHsJYRJGtuHkm6/s0oUSrgyoYoxMCUB9youH5H19CQgPEH2wEtRUIn+Yw/1WQSnBHf8gboB8fUpqnC4PKtTog5q1T8T/+ijXHys/n1ns6r0G52gG7UjVpYZX6a7basWQ+nUlSKYdCbY=
ARC-Authentication-Results: i=1; sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2233E4BA79BC
Message-ID: <897197ae-26c9-498e-b275-da16047182d1@maxrnd.com>
Date: Sat, 3 Oct 2026 01:12:53 -0700
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Race during the first use of pthread_rwlock_{rd,wr}lock from
PTHREAD_RWLOCK_INITIALIZER
To: cygwin AT cygwin DOT com
References: <1789871270892 DOT 1574718721 DOT 2143240182 AT gmail DOT com>
<db9fa568-9370-42c5-8789-3306cb407c0d AT maxrnd DOT com>
In-Reply-To: <db9fa568-9370-42c5-8789-3306cb407c0d@maxrnd.com>
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Mark Geisert via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Mark Geisert <mark AT maxrnd DOT com>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

Hello kikairoya,

On 9/20/2026 2:19 AM, Mark Geisert via Cygwin wrote:
> Hello kikairoya,
> 
> On 9/19/2026 8:34 PM, kikairoya via Cygwin wrote:
>> Hello,
>>
>> I've found a race during the first use of pthread_rwlock_{rd,wr}lock
>> (reproducer attached; requires -lsynchronization to build).
>>
>> Concurrent calls to pthread_rwlock_{rd,wr}lock on a rwlock initialized
>> with PTHREAD_RWLOCK_INITIALIZER can cause multiple internal
>> initializations, resulting in some locks being lost.
>>
>> It seems that pthread_rwlock::init (cygwin/thread.cc:2441) needs to
>> check whether the rwlock is still PTHREAD_RWLOCK_INITIALIZER while
>> holding rwlock_initialization_lock, as pthread_mutex::init does.
>>
>> pthread_cond::init appears to need the same fix as well.
> Thanks for the report and especially for the STC (simple test case).
> I will investigate further.
I've tried to fix the behavior you're seeing in two ways.  First by 
using ::is_initialized(rwlock) and second by seeing if *rwlock == 
PTHREAD_RWLOCK_INITIALIZER, each while holding rwlock_initialization_lock.

Restarting Cygwin with the first fix didn't get very far.. bash 
partially starts but exits immediately.  With the second fix bash seems 
OK but X Window clients can't start and sshd can't start either.  Your 
STC does operate correctly with the second fix to Cygwin.

I believe your STC is relying on undefined behavior of 
pthread_rwlock_init().  Because you have four threads contending for the 
same location in memory, the following sentence from the POSIX standard 
defining that function applies:
> Results are undefined if pthread_rwlock_init() is called specifying
> an already initialized read-write lock.

I assume (or you've already said ;-) you're comparing Cygwin with Linux. 
  Linux may well have a defined action for the situation that Cygwin 
doesn't.  I'm not sure how to proceed just yet.

..mark

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2026   by DJ Delorie     Updated Sep 20 2026