[m-users.] Threads and cc_multi-ness
Volker Wysk
post at volker-wysk.de
Mon Feb 20 17:43:42 AEDT 2023
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20230220/2994890e/attachment.sig>
More information about the users
mailing list