Mercury Bugs - mercury
View Issue Details
0000224mercuryBugpublic2011-10-24 11:592011-10-25 10:42
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000224: STM broken without --inline-compound-threshold 10 --loop-invariants
DescriptionAttached is a basic mutex implementation using STM primitives. Compile with:

mmc --parallel -O0 --inline-compound-threshold 10 --loop-invariants --rebuild stm_bug

And run. Program will behave as expected (uses 200% CPU on a multiproc platform, does not terminate).

Recompile without either one (or both) of "--inline-compound-threshold 10" or "--loop-invariants":

mmc --parallel -O0 --rebuild stm_bug

And run. Program soon terminates due to failed assertion about the state of the lock.

Behavior is identical under hlc.par grade (-H flag). Building without any optimization flags fails as well, since -O2 (the default) enables "--inline-compound-threshold 10" but not "--loop-invariants".
TagsNo tags attached.
Attached Files? stm_bug.m (1,008) 2011-10-24 11:59
patch stm.patch (762) 2011-10-25 10:41

2011-10-24 12:16   
Note: in more complex programs I see behavior which I believe is triggered by this bug even with these optimizations enabled. I will attach a test case later.
2011-10-24 14:40   
The whole STM implementation is experimental and incomplete. It was worked on by two honours students in the past; noone is working on it currently. Bugs in it won't be fixed until we get someone else who wants to work on the STM system.
2011-10-25 10:42   
There was a race condition in the STM runtime -- reading an STM variable read the physical location multiple times without a lock. Attached is a patch against CVS which fixes this.

Issue History
2011-10-24 11:59colandermanNew Issue
2011-10-24 11:59colandermanFile Added: stm_bug.m
2011-10-24 12:16colandermanNote Added: 0000369
2011-10-24 14:40zsNote Added: 0000370
2011-10-25 10:41colandermanFile Added: stm.patch
2011-10-25 10:42colandermanNote Added: 0000373