Mercury Bugs - mercury
View Issue Details
0000223mercuryBugpublic2011-10-24 08:022011-11-03 12:08
Reportercolanderman 
Assigned Towangp 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000223: thread.mvar.init/0 and thread.semaphore.init/1 should be marked impure
Descriptionthread.mvar.init/0 and thread.semaphore.init/1 are obviously impure but are not marked as such, leading to logical inconsistencies such as this:

main(!IO) :-
    M1 = init, M2 = init,
    put(M1, 1, !IO), take(M2, _, !IO).

not being equivalent to this:

main(!IO) :-
    M1 = init, M2 = M1,
    put(M1, 1, !IO), take(M2, _, !IO).

(The former will block but the latter will not.)

They should be marked impure or removed from the library.
TagsNo tags attached.
Attached Files

Notes
(0000368)
wangp   
2011-10-24 09:37   
That's true. They were added so that mvar and semaphore mutables could be initialised without the I/O state arguments. Before marking them impure, I would like to see either or both:

- mutables allowed to be initialised by impure functions
- mutables initialised by a predicate call with access to the I/O state
(0000371)
juliensf   
2011-10-24 16:10   
(1) mutables allowed to be initialised by impure functions

This would be fine, for consistency we should allow calls to semipure functions too.
(Once this is done mvar.init etc can just be made impure.)

(2) mutables initialised by a predicate call with access to the I/O state

This is a bit more tricky. The third argument of a mutable declaration is currently a value, not
a call. In order to have a predicate call in the third argument this will need to change and probably
in a way that will break quite a bit of code that already uses mutables.
(0000380)
wangp   
2011-11-03 12:08   
Fix committed.

Issue History
2011-10-24 08:02colandermanNew Issue
2011-10-24 09:37wangpNote Added: 0000368
2011-10-24 16:10juliensfNote Added: 0000371
2011-10-24 16:10juliensfStatusnew => acknowledged
2011-11-03 12:08wangpNote Added: 0000380
2011-11-03 12:08wangpStatusacknowledged => resolved
2011-11-03 12:08wangpResolutionopen => fixed
2011-11-03 12:08wangpAssigned To => wangp