[m-dev.] STM rewrite

Chris King colanderman at gmail.com
Wed Nov 9 14:50:14 AEDT 2011


Hi all,

The current (experimental) STM implementation has the following drawbacks:

* runtime bugs
  - race conditions (e.g. bug #224)
  - subtle bugs with nested logs
* syntax transformation bugs
  - treats STM blocks as pure and not linked to state, leading to
incorrect output (see attached)
  - mode analysis not completely applied (see attached)
* disjointed architecture
  - runtime code split between runtime and library
  - syntax transform recreates library code
* not implemented for backends other than C

Furthermore, one may make the following observations:

* retry() is not needed; Mercury already has a failure mechanism
* nested logs are not needed; Mercury already has backtrackable unique
modes (mostly_unique)
* or_else is not needed; Mercury already has if/then/else
* use of builtin failure allows determinism analysis to double as
wait-freedom check

Attached is a standalone-module implementation which does not exhibit
the above drawbacks and takes advantage of the above observations.
Forthcoming is a replacement for the atomic[] block syntactic sugar
which merely forwards all work to the library (similar to how try[]
blocks work).

(Note that due to bug #225 you must comment out the mutable
declaration in the source code for this module to compile in the .hlc
grade.)

Also attached is a demo program in which 20 threads repeatedly access
an mvar-like object in a highly contentious manner.

Comments, suggestions, and questions welcome.  I hope eventually for
this module to find its way into the standard library (no doubt
pending stylistic changes).

- Chris King
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stm.m
Type: application/octet-stream
Size: 22408 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20111108/4c94e0b0/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unif_bug.m
Type: application/octet-stream
Size: 307 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20111108/4c94e0b0/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stm_counter_borked.m
Type: application/octet-stream
Size: 720 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20111108/4c94e0b0/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stm_mvar.m
Type: application/octet-stream
Size: 2145 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20111108/4c94e0b0/attachment-0003.obj>


More information about the developers mailing list