From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 155163858C20 for ; Tue, 14 Nov 2023 10:20:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 155163858C20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 155163858C20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699957229; cv=none; b=DFfebN5w6iqdub/gKVJ3qifoT/k5p14OEVpUheXSjyhM9rcd4tM3eGJRciyWSmoXZtle5YdT6aouxMch/xvx1ML2Srf37HCxYhXqgTZaeEuwXyvvzi/8AFECohIsYm7OECxBTxcg9f9i7Bn7pZTTRUzkiYvSr1WIWJ8RqEN6nlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699957229; c=relaxed/simple; bh=lHotkTKJ5iRl7rcCRQ3n2s36qwCzPeB6VqAZM9Qd1Cw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=RdKQbu6294njUAFD4vgeADrNYsZ7cBESf4ItP+4v8tK3Cxsa1P6jYcvzLGd9306xtP/ZHl6noFj8nikvoSEI0w+tAAr1vRPcARblUXZbXuiGzuUC3f278X3+qwphuME76yaS/OMvZL/GnYW7mITy9nLuJBMq8L++Vxrx8vmglo8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699957227; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=7UFJFN2XSNZRgTBoAre0w+7w0NE9lB2pahXT9rcvePQ=; b=SqZXrBfmgm4K5CSYPyPEo76sWWBA/+b2C5YPjKgz64okjKUCczHjG3x33kCF7bFbhDFkqK +wWXcSrQP0In//84f06HUgdnSPa7gVRS5Z1oaOLriI4rAgelZHZHRjiH8KPzz+faoGj2Ko gKf1h8fST/n4bJhVTFXuxUglDIBPjCI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-u9Lv6wr5N8iNYyUqLN55bg-1; Tue, 14 Nov 2023 05:20:26 -0500 X-MC-Unique: u9Lv6wr5N8iNYyUqLN55bg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9721830965; Tue, 14 Nov 2023 10:20:25 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.39.194.184]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AEC8A492BE7; Tue, 14 Nov 2023 10:20:25 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 4E9F0A80A38; Tue, 14 Nov 2023 11:20:24 +0100 (CET) Date: Tue, 14 Nov 2023 11:20:24 +0100 From: Corinna Vinschen To: Glenn Strauss Cc: Bruno Haible , newlib@sourceware.org, cygwin@cygwin.com Subject: Re: rand is not ISO C compliant in Cygwin Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: Glenn Strauss , Bruno Haible , newlib@sourceware.org, cygwin@cygwin.com References: <9938355.c9vzh5UkMf@nimes> <4205183.RD5H4TdPZm@nimes> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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 List-Id: On Nov 13 17:14, Glenn Strauss wrote: > On Mon, Nov 13, 2023 at 10:33:48PM +0100, Bruno Haible via Cygwin wrote: > > POSIX does not have these two sentences, but instead has: > > > > "The rand() function need not be thread-safe." > > I read the above as requiring *reentrancy*, but not *thread-safety*. > > If multiple threads are accessing rand() and rand() accesses global > state, the global state should not get corrupted; the sequence > generated by rand() should remain intact. Since thread-safety is not > guaranteed, is it theoretically possible that multiple threads enter > rand() at nearly the same time and both get the *same* random value in > the sequence. (Whether or not that is undesirable behavior is > application-specific.) A mutex can avoid this theoretical duplication, > as can using thread-local state (with difference seeds) instead of > global state. If the seed value is the same in multiple threads using > thread-local state, the sequence of random values generated in each > thread will be repeated in each thread. This may be surprising behavior > to some when srand() is called, then multiple threads spawned, and each > thread subsequently gets the same sequence of values from rand(). That's a good common sense argument for changing rand() to use a global state. Corinna