delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2024/05/29/07:20:27

DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 44TBKQxk1627536
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=mAQre9ex
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A23ED3864C56
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1716981625;
bh=gaVYMglYlBESB7dlLQmPUYyON1XGgHcoV5bL/ww8eIg=;
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=mAQre9exuIaxXTmKVeJAV9SKf3nfEeniRqzpjvripbZB3fdB8W9d42BT+sLXO5Pwj
qi/S2I/sZHFyeq53FfNrmMajjkPmxQ0miQslHj2PEEy6K2GeYOiQXilJkHxF+qRJJL
I10Bf/vtfDR/hbdlePw+GsG3UpC/1Y94q75Y5Dlw=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8CE33858288
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8CE33858288
ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1716981602; cv=pass;
b=oIrGbs5hSQyhysxblWLPXv857LFiV7mU2Jaxvy8AWpGxnZs8SOZhKh21kevSP+rPTMhF9vIv0t08c9eK5ighu7u6HasayVTlpVXfZFsTnDzjVnlZ0a3e8ulO85f2ok1NN9zNbD4rZFCBKvTaBApSVBO4KLeR9UAGJwOkqUrLRck=
ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key;
t=1716981602; c=relaxed/simple;
bh=dHGRtk9/Ky1kvXc/EOL7cGMHLNeo5Tg5iAhkrGqZQjk=;
h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID:
MIME-Version;
b=c10sNAvBtxmLBY2uRcReHIhw6VtEnGXk7UK6XLbd5XtAqE9T/h6MQbDIVvFQVrO0wVKIYEAEWL1vCR60WgnXPG84A+zwH1EPpJPLvbTQx2XjG90tkKxtEFtIP8oYmCCLOU9aN7KkPqwsxKrbFY8S//iS+GUHv+xqeBHgR/Dn7Ag=
ARC-Authentication-Results: i=2; server2.sourceware.org
ARC-Seal: i=1; a=rsa-sha256; t=1716981599; cv=none;
d=strato.com; s=strato-dkim-0002;
b=VM7I2/yVZPGgp3Yp2MGAbT2Zzm6QDuCW9xF9e5Q6hZ69+k5dRU4qN88rmHEDbvKNIn
rPOKx+AbpKdrWRAN52nZWsNS//bLtDsVkVEdSCuGedxRVm0Zz72xxMzS7EwclXwnBuBG
KOWQPzlqKhk7y/Ru2nhCGN8JAZ4gOOKboHqt7Z8whPTnic5oLJ/N/Oej+A9KTkHax4MW
XAfFQIYz++9xwZ0ggV24O+QD/4Ds3R5pL1VaL6hviX7JXqQfkNxaVxHUayP4+1APWFcG
6FA9RrZmUPk1DthKOcyowwnn5ZgngQ6yDgA+OruVTg8e6c5u0aki64hE+KTEn5ewDheI
ZjOQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1716981599;
s=strato-dkim-0002; d=strato.com;
h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From:
Subject:Sender;
bh=M0mhyCMPJgfpc0YbMW0kNh7BBVK1c8eu/6hZUophZuc=;
b=nvXbAeS6e/EDx3xG+jnJlIrvtP+93iUu/S5Ex64UuR7m89fUGM1JMKiPTOPFZbO35+
cKU/UAZiMePoXi9G7qnt72lKqHrRlNZC8LPwEk/rZp+jwvSLyjjJdsBGxjf320Y0Kefo
J0jGHE1ZCQWTG5JvjsmPTHIB5cUv7sHNllgBnY2fWsyMMO3CBQzsSAAkeetFLqed+5Av
ZMRBeRRPvPUaYXrnws26zkIt96Wbkq1ByP+6npjlsQs8lN6+CnY3v2lj3ejrbERXU09Y
O9jKFwPD6WQeCGsPla6HmZkUq4/N4XC1KOnMI6SMZM9/4g1Z6TwAI8dvwoZECJJE3oKA
s6Dg==
ARC-Authentication-Results: i=1; strato.com;
arc=none;
dkim=none
X-RZG-CLASS-ID: mo00
X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPAiqFt2JhGvFnRN6BsfqrAeOb8"
To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>, cygwin AT cygwin DOT com
Subject: Re: [PATCH] Cygwin: pthread: Fix a race issue introduced by the
commit 2c5433e5da82
Date: Wed, 29 May 2024 13:19:59 +0200
Message-ID: <2024672.Jb7ZSddCyT@nimes>
In-Reply-To: <20240529103020.53514-1-takashi.yano@nifty.ne.jp>
References: <20240529103020 DOT 53514-1-takashi DOT yano AT nifty DOT ne DOT jp>
MIME-Version: 1.0
X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE,
RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=no 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 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: Bruno Haible via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Bruno Haible <bruno AT clisp DOT org>
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>

Takashi Yano wrote in cygwin-patches:
> To avoid race issues, pthread::once() uses pthread_mutex. This caused
> the handle leak which was fixed by the commit 2c5433e5da82. However,
> this fix introduced another race issue, i.e., the mutex may be used
> after it is destroyed. With this patch, do not use pthread_mutex in
> pthread::once() to avoid both issues. Instead, InterlockedExchage()
> is used.

This patch is bogus as well, because it allows one thread to return
from a pthread_once call while the other thread is currently
executing the init_routine and not yet done with it.

> +  if (!InterlockedExchange (&once_control->state, 1))
> +    init_routine ();
> return 0;
> }

There is no code after the init_routine () call here. This means
that other threads are not notified when the init_routine () call
is complete. Therefore this implementation *cannot* be correct.

See: Assume thread1 and thread2 call pthread_once on the same
once_control.

            thread1                      thread2
            -------                      -------

         enters pthread_once       enters pthread_once

         sets state to 1

                                   sees that state == 1

                                   returns from pthread_once

                                   executes code that assumes
                                   init_routine has completed

         starts executing
         init_routine

         finished executing
         init_routine

         returns from pthread_once

Bruno




-- 
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 © 2019   by DJ Delorie     Updated Jul 2019