Re: [m-users.] Threads and cc_multi-ness

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Am Montag, dem 20.02.2023 um 10:25 +1100 schrieb Julien Fischer:
> 
> On Sun, 19 Feb 2023, Volker Wysk wrote:
> 
> > I've tried a trivial program using threads:
> > 
> > 
> > :- pred main(io::di, io::uo) is cc_multi.
> > 
> > ...
> > 
> > main(!IO) :-
> >    spawn(thread(88), !IO),
> >    io.write_string("99\n", !IO).
> > 
> > :- pred thread(int, io, io).
> > :- mode thread(in, di, uo) is cc_multi.
> > 
> > thread(I, !IO) :-
> >    io.format("I=%i\n", [i(I)], !IO).
> > 
> > 
> > Both main/2 and my thread/3 need to be cc_multi. What surprises me, is that
> > I get a compiler warning:
> > 
> > 
> > threads.m:021: In `thread'(in, di, uo):
> > threads.m:021:   warning: determinism declaration could be tighter.
> > threads.m:021:   Declared `cc_multi', inferred `det'.
> > 
> > 
> > ... But the samples in samples/concurrency/dining_philosophers, which do it
> > like my trivial program, get compiled without such a warning message.
> > 
> > I think the warning isn't correct - the determinism declaration could NOT be
> > tighter. The mode of the spawn/3 predicate forbids making it "det".
> 
> That warning is produced by determinism analysis and it doesn't "know"
> that thread/3 will be used as an argument to spawn/3.
> 
> > So, what about this warning message? Just ignore?
> 
> Ignore it. There are a couple of ways to avoid it:
> 
> 1. Declare thread/3 to be cc_multi and call builtin.cc_multi_equal/2 in
> its body.
> 
>     thread(I, !IO) :-
>         io.format("I=%i\n", [i(I)], !IO),
>         cc_multi_equal(!IO).
> 
> 2. Wrap the first argument of spawn/3 in a cc_multi closure.
> 
>      spawn((pred(!.IO::di, !:IO::uo) is cc_multi :- thread(88, !IO)), !IO),
> 
> Julien.

Okay, thanks!

Volker

_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmPzFp4ACgkQ+K4ydFOs
HoXI4BAAsUdPides4MD4xtj9zO+ZtfXfYRn6o16QYWAOvL4kQ1hpdXThMvrcz1Um
ssdQ4eU49KZv148SgPFixDwB0yX1+7a3ItFB+BLgqHbsIOlwDz3y0kvd9b/+gzTJ
ToeyLyn5oPgGInMgVl8mOLPuTTV6EoZjRqggAhI8yDe5MbdxoWx/89hV/xvc8C8D
mUmgbQ4SWrGU/oCqQf9WSVTNtb7slbvi+JqVnieTqec1CntXauG1HDLVAPF5IsZi
5TrRH6/D8JBfFqu6/tszw8dsqwDC6eXj9ww5bJ9Duj8AFN3RnCiORKryRdxH8Ca+
GurIc26+OAiNH4D1uFYDq0ZVuDNUycm2ZnuVudPu0HpK2EBNKLtXGKD5JuJAObJP
LWLDte6jGhVq9ECXzklkdsSakicbypun0FKNQyTiDuMySRInNJPJ609leJh1alW1
QKyEy+tCD2vJqOac9PkFUWsefKzsSET7meZp781PZYZeV10tdMI26yX10ylmgpLY
f1PrQPaNNpDCBnFicNki38e1fIeCKefo4/AmT+7Pj+I5UrsB3AbyC30DA8D6Qrhd
avRSbDLeXXjzNsrLMCUizuzipAQmuj9DBgWJtUyy/ptHVn1KS0RtfwLz17i3x4Bz
MzmEIFc3A3KkKY0yRE/fq25O/uE2D7r1se/JcJ2OUH0wlxROhf0=
=QDxb
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.