Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Optimization hinders evolution.


devel / comp.unix.programmer / Re: POSIX example for pthread_join()

SubjectAuthor
* POSIX example for pthread_join()Spiros Bousbouras
`* POSIX example for pthread_join()Scott Lurndal
 `- POSIX example for pthread_join()Richard Kettlewell

1
POSIX example for pthread_join()

<3xHz3cHMGiagCl7tG@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10791&group=comp.unix.programmer#10791

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.programmer
Subject: POSIX example for pthread_join()
Date: Fri, 14 Jul 2023 11:05:52 -0000 (UTC)
Organization: To protect and to server
Message-ID: <3xHz3cHMGiagCl7tG@bongo-ra.co>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 14 Jul 2023 11:05:52 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="2019065"; posting-host="9H7U5kayiTdk7VIdYU44Rw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:vRjcb7F4IjC2Jb+Rwqb3oF7Ywch8uP/hRmlav/ty8wI=
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
X-Notice: Filtered by postfilter v. 0.9.3
 by: Spiros Bousbouras - Fri, 14 Jul 2023 11:05 UTC

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.

Re: POSIX example for pthread_join()

<oLdsM.360998$65y6.165763@fx17.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10792&group=comp.unix.programmer#10792

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mb-net.net!open-news-network.org!news.mind.de!bolzen.all.de!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: POSIX example for pthread_join()
Newsgroups: comp.unix.programmer
References: <3xHz3cHMGiagCl7tG@bongo-ra.co>
Lines: 17
Message-ID: <oLdsM.360998$65y6.165763@fx17.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 14 Jul 2023 15:23:00 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 14 Jul 2023 15:23:00 GMT
X-Received-Bytes: 1113
 by: Scott Lurndal - Fri, 14 Jul 2023 15:23 UTC

Spiros Bousbouras <spibou@gmail.com> 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);

Re: POSIX example for pthread_join()

<wwvo7kesbn5.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10793&group=comp.unix.programmer#10793

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.chmurka.net!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: inva...@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.unix.programmer
Subject: Re: POSIX example for pthread_join()
Date: Fri, 14 Jul 2023 17:25:50 +0100
Organization: terraraq NNTP server
Message-ID: <wwvo7kesbn5.fsf@LkoBDZeT.terraraq.uk>
References: <3xHz3cHMGiagCl7tG@bongo-ra.co>
<oLdsM.360998$65y6.165763@fx17.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
logging-data="100327"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:eMxehtMXVsizipcznARxu+VXNzc=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Fri, 14 Jul 2023 16:25 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Spiros Bousbouras <spibou@gmail.com> 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/

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor