[email protected] (Scott Lurndal) writes:
Spiros Bousbouras <[email protected]> writes:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html :
((subarray *)arg)->ar[i]++;
This seems to me to be undefined behaviour since arr[] is not >>initialised.
it's true that arr[] is not initialized. ar[] is, however.
int ar[1000000];
...
sb1.ar = &ar[0];
sb1.n = 500000;
(void) pthread_create(&th1, NULL, incer, &sb1);
There is no arr, but that’s just a typo.
I agree with Spiros. sb1.ar and sb2.ar are initialized; they point to
ar[0] and ar[500000] respectively. The contents of the ar array on
main’s stack are not initialized, so both threads will do an
uninitialized read on every iteration.
If the example was simpler it would be more likely to be correct l-)
--
https://www.greenend.org.uk/rjk/
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)