2024-12-10 11:12 AEDT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000224mercuryBugpublic2011-10-25 10:42
Reportercolanderman 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
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
  • ? file icon stm_bug.m (1,008 bytes) 2011-10-24 11:59
  • patch file icon stm.patch (762 bytes) 2011-10-25 10:41 -
    --- mercury/runtime/mercury_stm.c	2011-05-20 00:16:55.000000000 -0400
    +++ mercury-compiler-11.07-beta-2011-09-30-modded/runtime/mercury_stm.c	2011-10-24 19:37:24.723339594 -0400
    @@ -264,6 +264,7 @@
     {
         MR_STM_TransLog     *current_tlog;
         MR_STM_TransRecord  *current;
    +    MR_Word             value;
     
         current_tlog = tlog;
     
    @@ -293,10 +294,10 @@
         ** Add an entry that indicates that it has been read and then return
         ** the value that is stored in the transaction variable.
         */
    -    MR_STM_record_transaction(tlog, var, var->MR_STM_var_value,
    -        var->MR_STM_var_value);
    +    value = var->MR_STM_var_value;
    +    MR_STM_record_transaction(tlog, var, value, value);
     
    -    return var->MR_STM_var_value;
    +    return value;
     }
     
     void
    
    patch file icon stm.patch (762 bytes) 2011-10-25 10:41 +

-Relationships
+Relationships

-Notes

~0000369

colanderman (reporter)

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.

~0000370

zs (developer)

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.

~0000373

colanderman (reporter)

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.
+Notes

-Issue History
Date Modified Username Field Change
2011-10-24 11:59 colanderman New Issue
2011-10-24 11:59 colanderman File Added: stm_bug.m
2011-10-24 12:16 colanderman Note Added: 0000369
2011-10-24 14:40 zs Note Added: 0000370
2011-10-25 10:41 colanderman File Added: stm.patch
2011-10-25 10:42 colanderman Note Added: 0000373
+Issue History