DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 44UDsssP2123462
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=l2/sO27m
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C847385E45D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1717077292;
	bh=X0gHtJbwoEXE/6XLwiBfi8dGU+d9P5ayVXavu4Mb8/I=;
	h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=l2/sO27mRtb3t1lsj0y6MI8/8L0e0XhjH+BhcCGfXvHS5+H5j2Su3qrbRv1m7YVhM
	 gbAqnfAhp+3NCJQ3XzLiiFKAOxss6/GLjl/MlGz38EPVaiyAKDjcDHpW7koVL6h13d
	 HqTvjObY31Dtzx7WO9bAiJOgz3AN7KslbajtXsl8=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F6143858417
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2F6143858417
ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1717077236; cv=pass;
 b=B6riLIw1Lsv79f4HdbrZUYWsYzmwRUXHPQoXROs1H3q8QMXojSygIgLXBm0oKoh+zxCoZF9wjqjKSL74UkfT5QcgGMblXSi4iVmWP6zKgy4pV600h8pn+4GK7FAkCgoGUlmdxLwFfssUsi102GJVPkgkE0mQ9N3KuSt4u2SDBOI=
ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key;
 t=1717077236; c=relaxed/simple;
 bh=HrfCDELKy9aHRzUhJPIiRI9yeFdPeEAdJPFpJF0o3Lk=;
 h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID:
 MIME-Version;
 b=kVhqcOCHw5Xn5ge5vKdzU5WWENGsx9Tg6OyHp2Q38Duc3qSP5mLK6duXfLaB8xxV1oe9Rhx/BxHEgwW6uNnZiPNT8DV6jFfCqp/Zm/P+roKWcBOvSuUa4TgRQfTdL/ueuS2FeaE9vkJy9kPin3A5/aRJ7xX/KhesXJWIpw8G5I0=
ARC-Authentication-Results: i=2; server2.sourceware.org
ARC-Seal: i=1; a=rsa-sha256; t=1717077231; cv=none;
 d=strato.com; s=strato-dkim-0002;
 b=S1JbjrL0xRqlZKvdBS2nCKk2rx4Nni9IEYNpq04PTWfEuV2bdm0nZP4Dpo+x40sagb
 wPMJVGsKFPXUNhLOw0vs5uHZ70Ivi/PYM9Z6nQfYiIuq+OsEbZS/js2spxLzzVdsqkSB
 CTh8c+QmlFk/tz8i+VoUG9LrVrno4kRg8EvIlw/GSVzTWF833wYnCHZ9EJs2DXtLSuSq
 HhpzLS9GtTGsUDjBUNMfwfv084PVQskgoLmH/t47XkvDMHUpp+pxb6wBDYe+3K6IrZ5R
 NmXOh3EFBAZCb37NYhbG/byXT15njwc05s2d/+VmRL7F4EP/3iueWO0hpig9Ze8yc/v3
 N5Gg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1717077231;
 s=strato-dkim-0002; d=strato.com;
 h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From:
 Subject:Sender;
 bh=sBd62ujY9m1nrt2lYETuSvurj3R4AETKXENUzOwFyKw=;
 b=MdngQyAaXxhhSMKBCaSZC6g13C4AgqWcSqh87rATMIOpSktrPcu+2+1Jcb1Tk1fomm
 fcdpkIJA0IX6cNN02BQCRPEJCkGRYH0xyA7UmLB82SqUTZejU/SZQHHTu3gW47GmLZXD
 UCvHr+CF0BgktpN2dOZwTNKsXMSsx3inYCqVE7y5oQYeQx9pwYyyo3+eLQbLhY7+Yg4Z
 ONNMmEr/jTGGMDbcobQZhFH5qZlr8CyzRixJ3NB/gA62dsZVNkAeWoRgRCuL013HlxqZ
 5LenFE8oWxWn0iIyOr8XJoT+2aaM2oQ6JtkweP1db3SI99Al1J2xK9LexWM6w8DMDY0g
 Bokg==
ARC-Authentication-Results: i=1; strato.com;
    arc=none;
    dkim=none
X-RZG-CLASS-ID: mo00
X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpOfjqSRCBA3DxwVMPzYVsfrcNDf"
To: Takashi Yano <takashi.yano@nifty.ne.jp>, cygwin@cygwin.com,
        Noel Grandin <noelgrandin@gmail.com>
Subject: Re: SRW locks
Date: Thu, 30 May 2024 15:53:51 +0200
Message-ID: <3735091.4QnflXoHfv@nimes>
In-Reply-To: <233f8671-c1af-4587-bb83-a206a7e90090@gmail.com>
References: <20240530050538.53724-1-takashi.yano@nifty.ne.jp>
 <2073558.3YGTXZJOeS@nimes> <233f8671-c1af-4587-bb83-a206a7e90090@gmail.com>
MIME-Version: 1.0
X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE,
 RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP,
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Bruno Haible via Cygwin <cygwin@cygwin.com>
Reply-To: Bruno Haible <bruno@clisp.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

Noel Grandin wrote:
> > Still: Does ReleaseSRWLockExclusive notify other threads?
> > 
> 
> Of course? How else would a lock work, it must release other waiters?
> 
> It might not be a fair lock though, which is not a problem for this situation, which does not require fair locking.
> 
> 
> > Functionally, the INIT_ONCE looks interesting. But, like Takashi Yano mentioned,
> > how would you make it fit into a pthread_once_t that is defined as
> >    struct { pthread_mutex_t mutex; int state; }
> > ?
> 
> Something like:
> 
> struct once {
>     union {
>        pthread_mutex_t old_mutex_field_for_size_compatibility;
>        SRWLOCK lock = SRWLOCK_INIT;
>      };
>      int state;
> };

Reading [1], it seems that this might indeed work, and be faster than code
that uses CRITICAL_SECTIONs.

Still, something to watch out is this bug [2].

All in all, I would say that every such change ought to be tested with a
nontrivial test program that performs several thousands of rounds.

Bruno

[1] https://marabos.nl/atomics/os-primitives.html
[2] https://old.reddit.com/r/cpp/comments/1b55686/maybe_possible_bug_in_stdshared_mutex_on_windows/




-- 
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
