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.161]) by sourceware.org (Postfix) with ESMTPS id E1BD43858C66 for ; Tue, 14 Nov 2023 11:52:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1BD43858C66 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 E1BD43858C66 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.161 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1699962734; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=G9ftzBGzl5Gsumjh1bAUCr3mTZu4ofh11+T1vrecaj4=; b=Jk//W+9Z8zujEHAGLvNnNwXt6oXJuamuwhLKo1J+2Dhsaz0u3b+plfeMU2AbTd0Nf8 9GKjvwL72Pd+tKCLwBeRZK3/uyNp6ggCcUNr4PQAlnpab7g3m+PN+AH8J9vRIoTZo0n3 XLwQ/TrLzBvYyGb2g5STcVCxrRx12wBwJvECHFLebHBL2zXTx+9BdQslkTVp5sVY1V0h 8zUDQwaQPmuCCUU9H3pK/L/fbz2AVJoO1YcDO9Pl0AJjwqyX3OV5EEATeDnFicYkSOIz cuCYx+VfVnLew74i/5j7Cbiz7re20zyw8X8uMewkBAbbUorErRKJLuJSG2G53yJN22Jq SgZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1699962734; s=strato-dkim-0003; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=G9ftzBGzl5Gsumjh1bAUCr3mTZu4ofh11+T1vrecaj4=; b=Z7Fp+JLyDFTO/7WBJWPLYSlydnOyDRMMglYWm4CtgR8sSXWUsQSgu68h0oTjUxcotW ofcUtTVltk2I0MU41hAw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPA3qFfCT9Jw/Et2No03dzxS8YHkA==" Received: from nimes.localnet by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id D75765zAEBqD6mE (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 14 Nov 2023 12:52:13 +0100 (CET) From: Bruno Haible To: Bruno Haible , newlib@sourceware.org, cygwin@cygwin.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: References: <9938355.c9vzh5UkMf@nimes> <4205183.RD5H4TdPZm@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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 List-Id: 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