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 3F6C63858D32 for ; Tue, 14 Nov 2023 16:59:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F6C63858D32 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 3F6C63858D32 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=1699981198; cv=none; b=le/xNDkFQ9wzTyVAJ4SneANdss3/Yjm00TMI7j6JuEBy83lrHIQiCk9FZrvhy7Vu37R6qXQP2trBuM3XzQcTp6Sc2WZlNEdgQU3BXYBF2T862mZgCuCC1b2n3Lt6aklGnZwDxCrs7c6uXYm8BqyjC70ZBfAQXdBMVmneX3/XQjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699981198; c=relaxed/simple; bh=sKaIlyyU5wMKjqZQr9PBKYQTixkQMZaymBJmSp/Q3XU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=hvYRcONzVqlI7A70KA314Pnmk+IfRoZItNDsFAzf2dKW0tgY3k/ZzaVKoFrgCoopVsPJ0GMwTQmPLL6wfkzKvKkb5xplc8o0ZE+tKGRT/pxtGAGMDL3M0xcc2m1kRIpI7rFRq0rv+jVw/S/OHQnx9srqgFB+G1bk4PnbtsmAUGA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699981196; 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=NGwTvuufiP6fUq+o6qrU3HZ4mtX2PCqe9ISPwBSBVcc=; b=aV5N+EH+smqxUBpOJ/IpX5BO1kUnO+j6Rs1G8ae+PnyTD1wvvSpY5zL+VUNUjKoHont5yA 14wJGG0XuMf0iax8fPqfLBi+5Z3eYY2fEaUSEpSxxHV7MMEsPYXU31NG6P4PaPcAC7gocr 9NujC4SWWWvwev6zdcmXif9kQPP3epM= 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-190--jQUT8SbNpOaFtB9qfrScw-1; Tue, 14 Nov 2023 11:59:55 -0500 X-MC-Unique: -jQUT8SbNpOaFtB9qfrScw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 4117385A58B; Tue, 14 Nov 2023 16:59:55 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.39.194.184]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C6452166B26; Tue, 14 Nov 2023 16:59:55 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id AE95FA80A62; Tue, 14 Nov 2023 17:59:53 +0100 (CET) Date: Tue, 14 Nov 2023 17:59:53 +0100 From: Corinna Vinschen To: Bruno Haible Cc: 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: Bruno Haible , newlib@sourceware.org, cygwin@cygwin.com References: <9938355.c9vzh5UkMf@nimes> <4205183.RD5H4TdPZm@nimes> <6858244.H3tkzssBUc@nimes> MIME-Version: 1.0 In-Reply-To: <6858244.H3tkzssBUc@nimes> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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 14 12:52, Bruno Haible wrote: > 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. Ok, I pushed a Cygwin-only patch for now, which calls Cygwin's random(3) functions to implement rand(3), just as GLibC does it. Since that's entirely inside the Cygwin codebase, other newlib targets are not affected right now. They still have a rand(3) PRNG per execution unit using either struct _reent, or the thread_local implementation. Corinna