[m-rev.] for review: add two mvar operations

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Oct 20 12:52:07 AEDT 2011



On Thu, 20 Oct 2011, Peter Wang wrote:

> Branches: main, 11.07
>
> library/thread.mvar.m:
> 	Add two operations: mvar.read, mvar.try_put.
>
> NEWS:
> 	Announce the additions.

...

> %-----------------------------------------------------------------------------%
> %-----------------------------------------------------------------------------%
>
> @@ -109,5 +121,24 @@ mvar.put(mvar(Full, Empty, Ref), Data, !IO) :-
>     impure set_mutvar(Ref, Data),
>     semaphore.signal(Full, !IO).
>
> +:- pragma promise_pure(mvar.try_put/5).
> +
> +mvar.try_put(mvar(Full, Empty, Ref), Data, Success, !IO) :-
> +    semaphore.try_wait(Empty, Success, !IO),
> +    (
> +        Success = yes,
> +        impure set_mutvar(Ref, Data),
> +        semaphore.signal(Full, !IO)
> +    ;
> +        Success = no
> +    ).
> +

I suggest:


      promise_pure (
          sempahore.try_wait(Empty, Success, !IO),
 	 (
  		Succeess = yes,
 		...
 	 )
      )

rather than the explicit promise_pure/1 pragams.  Likewise for the other
one.


> +:- pragma promise_pure(mvar.read/4).
> +
> +mvar.read(mvar(Full, _Empty, Ref), Data, !IO) :-
> +    semaphore.wait(Full, !IO),
> +    impure get_mutvar(Ref, Data),
> +    semaphore.signal(Full, !IO).

That looks fine otherwise.

Julien.
--------------------------------------------------------------------------
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