X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D91A3889823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1699892490; bh=BQgq5Xwf7T6K7/l1yDEzOd004g/Jqtzl/n+QmTlyzBw=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RV70nBBkL6wq2oF10BwTbDnn1K5AKu2lauPZKNitp+fcaBGmSi6qQdBqUrhTwSFiV ++onI8P3teeUDkDBUccJIIpNl7bRWXwdGMUA55CpPeTILdg8fAmpdroe47z36eEGOu OpBOlHWGRDpc1mK5MCfOTPOdG/16f22+n7bD4DVk= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3B3A3853315 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D3B3A3853315 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699892477; cv=none; b=Kj7ovMnTTeo+sFRSsDGLQq+C2yjtYEMfmCUZpp6VgZMah33TvTpRgD8Pdqt6nDAABLuEVzND1PYH8EJKSGf+dClVGrcnr4bgocsJu8u9T+oYHsP/lck7T/BHZTOoXjE6t31TlQOqjtWj8f+hHgrtflV4r97jU79czfXo9WiHS4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699892477; c=relaxed/simple; bh=TdQotI1OeS+/0Meim+UhirUXlJAI0dGdIag53iUHRDs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=VlUZiiXuHJjCbTucZhhMDylAYLyO1ZiqH6avF8GvcrcWSc7bTo75feADfoyS10y8LkfsD7CxIZ0uhdGYIkCeWWzGQ+YF3TXMYUr7N4KqkRkyTmqfEr0WfSNaP/PZDrbFLIVNY4/nnd3q6C23ZwdeYLfbs4EpjXP+WEELtYBHmNY= ARC-Authentication-Results: i=1; server2.sourceware.org X-MC-Unique: 25usbKz4MsiHfx9S7j3YVw-1 Date: Mon, 13 Nov 2023 17:21:02 +0100 To: Bruno Haible Subject: Re: rand is not ISO C compliant in Cygwin Message-ID: Mail-Followup-To: Bruno Haible , newlib AT sourceware DOT org, cygwin AT cygwin DOT com References: <9938355 DOT c9vzh5UkMf AT nimes> <4746602 DOT Hd9D3QOfv1 AT nimes> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.1 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Corinna Vinschen via Cygwin Reply-To: newlib AT sourceware DOT org Cc: Corinna Vinschen , newlib AT sourceware DOT org, cygwin AT cygwin DOT com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Nov 13 15:38, Corinna Vinschen wrote: > On Nov 13 15:25, Bruno Haible wrote: > > Corinna Vinschen wrote: > > > The rand() function would still not use locking but AFAICS that's > > > not actually required by POSIX or ISO C. > > > > Correct. Those who want an MT-safe rand-like function need to use random(), > > not rand(). I took a look into POSIX and I'm a bit puzzled now. From https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html RATIONAL The ISO C standard rand() and srand() functions allow per-process ^^^^^ (not requires) pseudo-random streams shared by all threads. Those two functions need not change, but there has to be mutual-exclusion that prevents interference between two threads concurrently accessing the random number generator. Ok, so, *iff* rand/srand share per-process state, then they have to use locking to prevent MT interference. POSIX continues: With regard to rand(), there are two different behaviors that may be wanted in a multi-threaded program: 1. A single per-process sequence of pseudo-random numbers that is shared by all threads that call rand() 2. A different sequence of pseudo-random numbers for each thread that calls rand() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I read this as the newlib technique being one way of correctly implementing rand/srand, no? Corinna -- 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