From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.163]) by sourceware.org (Postfix) with ESMTPS id C8CE33858288 for ; Wed, 29 May 2024 11:20:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8CE33858288 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=clisp.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=clisp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8CE33858288 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.163 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1716981599; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=M0mhyCMPJgfpc0YbMW0kNh7BBVK1c8eu/6hZUophZuc=; b=fpD+ysqn1vJYdCi6oZ13zoW8P8HWs3jSRo2QD5+sPPDAgKiKmEFiTMwejbhGhbzS0W AG0aUGiLaCen7UohehyYdrCxAhnJOuAOO+rlfVdmr0fZa3dX4C6mjW0sPMZcZfdIQIqC kIRsapHjdlb+vQ4pPXpngKxJT/vu7auebg2hxuDzg+TuMBzQHpzmkCsqGgc0l3HCaQrT G82D+x1LMsMNSzgyslXkq3mn+NQGm9d59fsu+SwNhFfXaHdpwAWr39qjODQIkXIVEdpt J6WLqxM2kgTcqdU8ccZjzUiDJ/DcqBOBSTuwXN91WLmSxyg31Gxn0SHvgJohgsw6RoJa WXVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1716981599; s=strato-dkim-0003; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=M0mhyCMPJgfpc0YbMW0kNh7BBVK1c8eu/6hZUophZuc=; b=OZcFxJXzqd7+/JcfEUG7+uPG1r7p4xDbLgLeJJCQ2jnaCIuifJetNxFgDnJvAGilEe fYiFkft2I7qOebK2d0DA== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPAiqFt2JhGvFnRN6BsfqrAeOb8" Received: from nimes.localnet by smtp.strato.de (RZmta 50.5.0 AUTH) with ESMTPSA id Ndd2ca04TBJxWh9 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 29 May 2024 13:19:59 +0200 (CEST) From: Bruno Haible To: Takashi Yano , cygwin@cygwin.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.53514-1-takashi.yano@nifty.ne.jp> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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 List-Id: 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