Re: rand is not ISO C compliant in Cygwin

2023-11-14 Thread Bruno Haible via Cygwin
Corinna Vinschen wrote: > 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. Thanks! -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:

Re: rand is not ISO C compliant in Cygwin

2023-11-14 Thread Corinna Vinschen via Cygwin
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 > >

Re: rand is not ISO C compliant in Cygwin

2023-11-14 Thread Bruno Haible via Cygwin
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

Re: rand is not ISO C compliant in Cygwin

2023-11-14 Thread Corinna Vinschen via Cygwin
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

Re: rand is not ISO C compliant in Cygwin

2023-11-14 Thread Corinna Vinschen via Cygwin
Hi Bruno, On Nov 13 22:33, Bruno Haible via Cygwin wrote: > Corinna Vinschen wrote: > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html > > [...] > > With regard to rand(), there are two different behaviors that may be > > wanted in a multi-threaded program: > > > > 1.

Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Glenn Strauss via Cygwin
On Mon, Nov 13, 2023 at 10:33:48PM +0100, Bruno Haible via Cygwin wrote: > Corinna Vinschen wrote: > > I took a look into POSIX and I'm a bit puzzled now. From > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html > > Part of the confusion is that POSIX and ISO C have slightly

Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Bruno Haible via Cygwin
Corinna Vinschen wrote: > I took a look into POSIX and I'm a bit puzzled now. From > https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html Part of the confusion is that POSIX and ISO C have slightly different wording. This POSIX page says: "The functionality described on this

RE: [EXTERNAL] Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Lavrentiev, Anton (NIH/NLM/NCBI) [C] via Cygwin
IMHO: > 2. A different sequence The word "different" in this context is ambiguous: is it "unrelated" as a generator, or is it "not the same" sequence of the actual numbers? > I read this as the newlib technique being one way of correctly implementing > rand/srand, no? If the first, then

Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Corinna Vinschen via 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

Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Corinna Vinschen via Cygwin
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(). FTR, we have to differ

Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Bruno Haible via Cygwin
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(). Bruno -- Problem reports: https://cygwin.com/problems.html FAQ:

Re: rand is not ISO C compliant in Cygwin

2023-11-13 Thread Corinna Vinschen via Cygwin
[redirecting to the newlib mailing list] This is long-standing code in newlib, not actually inside Cygwin. On Nov 10 21:19, Bruno Haible via Cygwin wrote: > ISO C 23 § 7.24.2.1 and 7.24.2.2 document how rand() and srand() are > expected to behave. In particular: > "The srand function uses the

Re: rand is not ISO C compliant in Cygwin

2023-11-11 Thread Allen, Norton T. via Cygwin
On 11/11/2023 1:25 PM, René Berber via Cygwin wrote: On 11/11/2023 10:50 AM, Allen, Norton T. via Cygwin wrote: [snip] The srand function is not required to avoid data races with other     calls to pseudo-random sequence generation functions. ..." That is not the same as "... required never

Re: rand is not ISO C compliant in Cygwin

2023-11-11 Thread René Berber via Cygwin
On 11/11/2023 10:50 AM, Allen, Norton T. via Cygwin wrote: [snip] The srand function is not required to avoid data races with other     calls to pseudo-random sequence generation functions. ..." That is not the same as "... required never to avoid data races ...". "not required" means the

Re: rand is not ISO C compliant in Cygwin

2023-11-11 Thread Allen, Norton T. via Cygwin
On 11/10/2023 5:27 PM, Bruno Haible wrote: Norton Allen wrote: Cygwin/(newlib?) has chosen to avoid race conditions by making pseudo-random sequences in different threads independent. Although the standard does not require this, it does not prohibit it either. I disagree. I cited the relevant

Re: rand is not ISO C compliant in Cygwin

2023-11-10 Thread Bruno Haible via Cygwin
Norton Allen wrote: > Cygwin/(newlib?) has chosen to avoid race conditions by making > pseudo-random sequences in different threads independent. Although the > standard does not require this, it does not prohibit it either. I disagree. I cited the relevant sentences from the standard. Other

Re: rand is not ISO C compliant in Cygwin

2023-11-10 Thread Norton Allen via Cygwin
On 11/10/2023 3:19 PM, Bruno Haible via Cygwin wrote: ISO C 23 § 7.24.2.1 and 7.24.2.2 document how rand() and srand() are expected to behave. In particular: "The srand function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to

rand is not ISO C compliant in Cygwin

2023-11-10 Thread Bruno Haible via Cygwin
ISO C 23 § 7.24.2.1 and 7.24.2.2 document how rand() and srand() are expected to behave. In particular: "The srand function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand. If srand is then called with the same seed value,