[m-rev.] for review: disallow impure parallel conjuncts

Peter Wang wangp at students.cs.mu.oz.au
Wed Aug 16 19:01:47 AEST 2006

On 2006-08-16, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> On Tue, 15 Aug 2006, Peter Wang wrote:
> >Estimated hours taken: 1.5
> >Branches: main
> >
> >Disallow impure parallel conjuncts as they can introduce concurrency 
> >issues.
> >e.g. in the following X could be bound to `foo' or `bar' in different runs.
> >
> >   impure set_mutvar(foo),
> >   (
> >	semipure get_mutvar(X)
> >   &
> >	impure set_mutvar(bar)
> >   )
> Is that a reason for disallowing them though?  Presumably at some point
> I'm going to have to promise that is pure - if there are concurrency
> issues then either the promise is a lie.

It depends what you want the semantics of parallel conjunction to be.  I
think it is intended for parallelism, and if you wanted concurrency
you'd use spawn/3.

> I don't necessarily see
> why the following should be not allowed:
>      (
>         impure foo
>      &
>         impure something_unrelated_to_foo
>      )
> If the code is impure then it is up to the programmer to ensure its
> correctness.

The compiler is conservative about the ordering of impure goals in
sequential programs, too, I don't see why that should change with
parallelism.  If we were talking about concurrent conjunction,

There *is* a way to allow impure conjunctions and preserve sequential
semantics.  In a parallel conjunction A & B, all the goals in B must be
delayed until the rightmost impure goal in A is finished.  The rest of A
and the start of B can then proceed in parallel, but the leftmost impure
goal in B must wait until A is completely finished.  This could be
implemented similarly to dependent parallel conjunctions, but I think it
would be a waste of time.


mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au

More information about the reviews mailing list