delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/11/14/06:52:33

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AB7138582B0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1699962752;
bh=TeyUAEL/mTKsbM8Lk2ophuoSz9FcPPEOkgBBSx4mDC8=;
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=LDLTK1eNHJ8126bSaXWxPPOhV39j1k76eA2wjFn7i9U/P3ZJS9HcZ8rfr92al6kRb
2JGDOq6fG1aQYmGjLAEm1lSasDlNujU2hQtRJjstpUJFlLECX0rUViOdBNVfhcFVGw
ei8oahRxWPau9LBiIoaGMe09BvaTnn5o+dmcWiRM=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1BD43858C66
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E1BD43858C66
ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1699962738; cv=pass;
b=HA52j0h4BwsQHEjuuHWZ1IlrZQAl9UKwOowz0VFJDc/oeFClGEDGtJA31B4tvt7eAjnMo36ZhnS2fZz/NrqjE9n8V1972YLZ1DDcdIM+ehbKBcgE6fyH0/5RpFPRVw0G9rTKZUYOpznowhGMspIrsbOIq8jGnVAMZ66eI9zYmLY=
ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key;
t=1699962738; c=relaxed/simple;
bh=g1wVP1Z3EXtchFVFr8mcJrwDVXt/yyGNaknkfaXlPgc=;
h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID:
MIME-Version;
b=QZyxruPBITE6evkTGMLYv8LMD/bDQ6j+ceNBhVMxTB8oH1vbNqExya1jsS2uopIduP3NgOCBXmyiWnPDpMsfo+r63waph3HhokcFSSPS8WavqE0wGxwK1eRG7oryWIeK6+ceqO56sb6H1zdRiZdDMddiX9Z3oiRp97IRA7fXqpE=
ARC-Authentication-Results: i=2; server2.sourceware.org
ARC-Seal: i=1; a=rsa-sha256; t=1699962734; cv=none;
d=strato.com; s=strato-dkim-0002;
b=kb/HE1xgxmUN9jx7F+DWIeQduO1sFCXnVLP0ILREYJq8M9IWSpbEKigAbo2lqU9RV1
kgLYMlE6WY1OSexYBr3NplZYB2L94APd86TS+jJLVI6085N8D/sj7VBHKjiSIRafU0mh
02IAG/nQMXOzAVgTzPM6g2n92ZZdz/l3Iz0j3nXxiM8VMHTjYYdSkD/hiYahelqzE92j
jDUi0rlgfTyKQFnxLkhjGqUGntV7CkohBTQB5NO0aLWjGWcKtwG17/bN9NPS3Ba7BJgg
CJpxUk6ILHDEPtYYeJteKhdjI0g0syfVDrRhCTiqdjlt0/ySQwmq6OnwsLlX2NTkHFkE
ln5A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1699962734;
s=strato-dkim-0002; d=strato.com;
h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From:
Subject:Sender;
bh=G9ftzBGzl5Gsumjh1bAUCr3mTZu4ofh11+T1vrecaj4=;
b=iGr+b3D22Y6FKa3B8Yrpyg9bab1c/3UzqVEswnGMzOVrxfwr8Mr5rrd1yajZIBtaOG
qrZbV6qrJtDT2CAu8YoDdJMwKK27G7EDXA2OIJJR29RSjdObBwwu2vG+RmBJ3NEHCPM3
qCsRicm629demwMLgQ8PZqx7E87khDAZgllnHpwsEcIXGbafjaxyJWeAI1aZ2WaqFmEV
3GCVAp+2JFND0+XxnynA75sgnX3aUOP1fANX+pK4toTVRMxhqt2CLE8QgNzzwKbClHBN
1ZzovEWmkBCDoutbOCA/LLxJPi9f2pveGBJxE2YiOzu82SAMUEW0jpoFqNmDaTVvfBuF
lPAg==
ARC-Authentication-Results: i=1; strato.com;
arc=none;
dkim=none
X-RZG-CLASS-ID: mo00
X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPA3qFfCT9Jw/Et2No03dzxS8YHkA=="
To: Bruno Haible <bruno AT clisp DOT org>, newlib AT sourceware DOT org, cygwin AT cygwin DOT com
Subject: Re: rand is not ISO C compliant in Cygwin
Date: Tue, 14 Nov 2023 12:52:13 +0100
Message-ID: <6858244.H3tkzssBUc@nimes>
In-Reply-To: <ZVNHtZ+US0LFcfY3@calimero.vinschen.de>
References: <9938355 DOT c9vzh5UkMf AT nimes> <4205183 DOT RD5H4TdPZm AT nimes>
<ZVNHtZ+US0LFcfY3 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,
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 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>

Corinna Vinschen wrote:
> > My understanding of this paragraph is:
> >   - If an application wants 1., they can use rand_r with SEED pointing
> >     to a global variable.
> >   - If an application wants 2., they can use rand_r with SEED pointing
> >     to a per-thread variable.
> 
> The problem I have with bringing rand_r() into the picture at this point
> is two-fold:
> 
> - The paragraph explicitely states "With regard to rand() ..."
> 
> - rand_r() is obsolescent and may be removed in a future version.

This paragraph is not directed at the libc implementor; it is directed at
the application programmer. Because
  - Otherwise the phrase "may be wanted in a multi-threaded program"
    would not make sense.
  - The goals "1. A single per-process sequence of pseudo-random numbers"
    and "2. A different sequence of pseudo-random numbers for each thread"
    cannot be achieved at the same time, since rand() takes no argument.

> I don't see that the vague expression "the modified thread-safe function"
> is really meant to be rand_r(), or rather rand() after an implementation decides
> to make rand() thread-safe.

It must mean rand_r(), because rand() cannot satisfy both goals at the
same time.

> However, what sense is there in providing a global
> state, while at the same time rand() doesn't need to be thread-safe.  In
> the end, if you call srand() once and then run rand() in concurrent
> threads, the implementation has no control over the sequences generated
> per-thread, unless your application threads will sync the calls explicitely.

The sense is reproducibility across threads. The standards comittee
probably wanted as little thread-specific verbiage at this place.

The two sentences added in ISO C 11 mean that the application needs to
sync their threads by itself, yes. But that's not uncommon: Every use of,
say, a global linked-list or hash table object accessed by multiple threads
needs the same precaution.

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